]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Use dynamically allocated image_desc_t.graphfile 643/head
authorJean-Michel Vourgère <nirgal@debian.org>
Sun, 2 Aug 2015 13:58:22 +0000 (15:58 +0200)
committerJean-Michel Vourgère <nirgal@debian.org>
Sun, 2 Aug 2015 16:38:46 +0000 (18:38 +0200)
PATH_MAX is unavailable on hurd platform.
Thanks to Marc Dequènes.

src/rrd_graph.c
src/rrd_graph.h
src/rrd_xport.c

index 47c4dcb08c5506728eda088f7fa975bdc22953a0..82042d4deb7802b18331b82518333a7ede814786 100644 (file)
@@ -404,6 +404,8 @@ int im_free(
     if (im == NULL)
         return 0;
 
+    free(im->graphfile);
+
     if (im->daemon_addr != NULL)
       free(im->daemon_addr);
 
@@ -3339,7 +3341,7 @@ int lazy_check(
 
     if (im->lazy == 0)
         return 0;       /* no lazy option */
-    if (strlen(im->graphfile) == 0)
+    if (im->graphfile == NULL)
         return 0;       /* inmemory option */
     if (stat(im->graphfile, &imgstat) != 0)
         return 0;       /* can't stat */
@@ -4263,7 +4265,7 @@ int graph_cairo_setup (image_desc_t *im)
 #ifdef CAIRO_HAS_PDF_SURFACE
     case IF_PDF:
         im->gridfit = 0;
-        im->surface = strlen(im->graphfile)
+        im->surface = im->graphfile
             ? cairo_pdf_surface_create(im->graphfile, im->ximg * im->zoom,
                                        im->yimg * im->zoom)
             : cairo_pdf_surface_create_for_stream
@@ -4273,7 +4275,7 @@ int graph_cairo_setup (image_desc_t *im)
 #ifdef CAIRO_HAS_PS_SURFACE
     case IF_EPS:
         im->gridfit = 0;
-        im->surface = strlen(im->graphfile)
+        im->surface = im->graphfile
             ?
             cairo_ps_surface_create(im->graphfile, im->ximg * im->zoom,
                                     im->yimg * im->zoom)
@@ -4284,7 +4286,7 @@ int graph_cairo_setup (image_desc_t *im)
 #ifdef CAIRO_HAS_SVG_SURFACE
     case IF_SVG:
         im->gridfit = 0;
-        im->surface = strlen(im->graphfile)
+        im->surface = im->graphfile
             ?
             cairo_svg_surface_create(im->
                                      graphfile,
@@ -4336,13 +4338,14 @@ int graph_cairo_finish (image_desc_t *im)
     {
         cairo_status_t status;
 
-        status = strlen(im->graphfile) ?
+        status = im->graphfile ?
             cairo_surface_write_to_png(im->surface, im->graphfile)
             : cairo_surface_write_to_png_stream(im->surface, &cairo_output,
                                                 im);
 
         if (status != CAIRO_STATUS_SUCCESS) {
-            rrd_set_error("Could not save png to '%s'", im->graphfile);
+            rrd_set_error("Could not save png to '%s'",
+                im->graphfile ? im->graphfile : "memory");
             return 1;
         }
         break;
@@ -4356,7 +4359,7 @@ int graph_cairo_finish (image_desc_t *im)
     case IF_JSONTIME:
       break;
     default:
-        if (strlen(im->graphfile)) {
+        if (im->graphfile) {
             cairo_show_page(im->cr);
         } else {
             cairo_surface_finish(im->surface);
@@ -4563,19 +4566,15 @@ rrd_info_t *rrd_graph_v(
         return NULL;
     }
 
-    if (strlen(argv[optind]) >= MAXPATH) {
-        rrd_set_error("filename (including path) too long");
-        rrd_info_free(im.grinfo);
-        im_free(&im);
-        return NULL;
-    }
-
-    strncpy(im.graphfile, argv[optind], MAXPATH - 1);
-    im.graphfile[MAXPATH - 1] = '\0';
-
-    if (strcmp(im.graphfile, "-") == 0) {
-        im.graphfile[0] = '\0';
-    }
+    if (strcmp(argv[optind], "-") != 0) {
+        im.graphfile = strdup(argv[optind]);
+        if (im.graphfile == NULL) {
+            rrd_set_error("cannot allocate sufficient memory for filename length");
+            rrd_info_free(im.grinfo);
+            im_free(&im);
+            return NULL;
+        }
+    } /* else we work in memory: im.graphfile==NULL */
 
     rrd_graph_script(argc, argv, &im, optind+1);
 
@@ -4598,7 +4597,7 @@ rrd_info_t *rrd_graph_v(
 
     if (im.imginfo && *im.imginfo) {
         rrd_infoval_t info;
-        char     *path;
+        char     *path = NULL;
         char     *filename;
 
         if (bad_format_imginfo(im.imginfo)) {
@@ -4606,8 +4605,12 @@ rrd_info_t *rrd_graph_v(
             im_free(&im);
             return NULL;
         }
-        path = strdup(im.graphfile);
-        filename = basename(path);
+        if (im.graphfile) {
+            path = strdup(im.graphfile);
+            filename = basename(path);
+        } else {
+            filename = "memory";
+        }
         info.u_str =
             sprintf_alloc(im.imginfo,
                           filename,
index 8c62ef737569ae3d3c76c8f049db1923708ea0a1..2c6930e0fd6c16afa6126dfe6c85cac252f81d71 100644 (file)
 #include <glib.h>
 
 
-#ifdef WIN32
-#  include <windows.h>
-#  define MAXPATH MAX_PATH
-#endif
-
 #define ALTYGRID        0x01   /* use alternative y grid algorithm */
 #define ALTAUTOSCALE    0x02   /* use alternative algorithm to find lower and upper bounds */
 #define ALTAUTOSCALE_MIN 0x04   /* use alternative algorithm to find lower bounds */
@@ -270,7 +265,7 @@ typedef struct graph_desc_t {
 typedef struct image_desc_t {
 
     /* configuration of graph */
-    char      graphfile[MAXPATH];   /* filename for graphic */
+    char      *graphfile;   /* filename for graphic */
     enum      gfx_type_en graph_type; /* type of the graph */
     long      xsize, ysize; /* graph area size in pixels */
     struct gfx_color_t graph_col[__GRC_END__];  /* real colors for the graph */
index 76f94b6b9bd7992a22eb907ce80fb3c7834ce192..610cded99d0eedc375cfb00d58ffed8b9f51c726 100644 (file)
@@ -394,7 +394,7 @@ int rrd_graph_xport(image_desc_t *im) {
   }
 
   /* if we write a file, then open it */
-  if (strlen(im->graphfile)) {
+  if (im->graphfile) {
     buffer.file=fopen(im->graphfile,"w");
   }