From: Jean-Michel Vourgère Date: Sun, 2 Aug 2015 13:58:22 +0000 (+0200) Subject: Use dynamically allocated image_desc_t.graphfile X-Git-Tag: v1.5.4~12^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F643%2Fhead;p=thirdparty%2Frrdtool-1.x.git Use dynamically allocated image_desc_t.graphfile PATH_MAX is unavailable on hurd platform. Thanks to Marc Dequènes. --- diff --git a/src/rrd_graph.c b/src/rrd_graph.c index 47c4dcb0..82042d4d 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -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, diff --git a/src/rrd_graph.h b/src/rrd_graph.h index 8c62ef73..2c6930e0 100644 --- a/src/rrd_graph.h +++ b/src/rrd_graph.h @@ -30,11 +30,6 @@ #include -#ifdef WIN32 -# include -# 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 */ diff --git a/src/rrd_xport.c b/src/rrd_xport.c index 76f94b6b..610cded9 100644 --- a/src/rrd_xport.c +++ b/src/rrd_xport.c @@ -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"); }