g_object_unref(im->layout);
}
+ if (im->ylegend)
+ free(im->ylegend);
+ if (im->title)
+ free(im->title);
+ if (im->watermark)
+ free(im->watermark);
+ if (im->xlab_form)
+ free(im->xlab_form);
+ if (im->second_axis_legend)
+ free(im->second_axis_legend);
+ if (im->second_axis_format)
+ free(im->second_axis_format);
+ if (im->primary_axis_format)
+ free(im->primary_axis_format);
return 0;
}
|| (nlabels == 1
&& (YN < im->yorigin - im->ysize || YN > im->yorigin))) {
if (im->symbol == ' ') {
- if (im->primary_axis_format[0] == '\0'){
+ if (im->primary_axis_format == NULL || im->primary_axis_format[0] == '\0') {
if (im->extra_flags & ALTYGRID) {
snprintf(graph_label, sizeof graph_label,
im->ygrid_scale.labfmt,
}
} else {
char sisym = (i == 0 ? ' ' : im->symbol);
- if (im->primary_axis_format[0] == '\0'){
+ if (im->primary_axis_format == NULL || im->primary_axis_format[0] == '\0') {
if (im->extra_flags & ALTYGRID) {
snprintf(graph_label,sizeof graph_label,
im->ygrid_scale.labfmt,
if (im->second_axis_scale != 0){
char graph_label_right[100];
double sval = im->ygrid_scale.gridstep*(double)i*im->second_axis_scale+im->second_axis_shift;
- if (im->second_axis_format[0] == '\0'){
+ if (im->second_axis_format == NULL || im->second_axis_format[0] == '\0') {
if (!second_axis_magfact){
double dummy = im->ygrid_scale.gridstep*(double)(sgrid+egrid)/2.0*im->second_axis_scale+im->second_axis_shift;
auto_scale(im,&dummy,&second_axis_symb,&second_axis_magfact);
if (im->second_axis_scale != 0){
char graph_label_right[100];
double sval = value*im->second_axis_scale+im->second_axis_shift;
- if (im->second_axis_format[0] == '\0'){
+ if (im->second_axis_format == NULL || im->second_axis_format[0] == '\0') {
if (im->extra_flags & FORCE_UNITS_SI) {
double mfac = 1;
char *symb = "";
}
/* yaxis unit description */
- if (im->ylegend[0] != '\0'){
+ if (im->ylegend && im->ylegend[0] != '\0') {
gfx_text(im,
im->xOriginLegendY+10,
im->yOriginLegendY,
RRDGRAPH_YLEGEND_ANGLE, GFX_H_CENTER, GFX_V_CENTER, im->ylegend);
}
- if (im->second_axis_legend[0] != '\0'){
+ if (im->second_axis_legend && im->second_axis_legend[0] != '\0') {
gfx_text( im,
im->xOriginLegendY2+10,
im->yOriginLegendY2,
im->
text_prop[TEXT_PROP_TITLE].
font_desc,
- im->tabwidth, 0.0, GFX_H_CENTER, GFX_V_TOP, im->title);
+ im->tabwidth, 0.0, GFX_H_CENTER, GFX_V_TOP, im->title?im->title:"");
/* rrdtool 'logo' */
if (!(im->extra_flags & NO_RRDTOOL_TAG)){
water_color = im->graph_col[GRC_FONT];
-90, GFX_H_LEFT, GFX_V_TOP, "RRDTOOL / TOBI OETIKER");
}
/* graph watermark */
- if (im->watermark[0] != '\0') {
+ if (im->watermark && im->watermark[0] != '\0') {
water_color = im->graph_col[GRC_FONT];
water_color.alpha = 0.3;
gfx_text(im,
return 0;
}
- if(im->watermark[0] != '\0') {
+ if (im->watermark && im->watermark[0] != '\0') {
Ywatermark = im->text_prop[TEXT_PROP_WATERMARK].size * 2;
}
// calculate the width of the left vertical legend
- if (im->ylegend[0] != '\0') {
+ if (im->ylegend && im->ylegend[0] != '\0') {
Xvertical = im->text_prop[TEXT_PROP_UNIT].size * 2;
}
// calculate the width of the right vertical legend
- if (im->second_axis_legend[0] != '\0') {
+ if (im->second_axis_legend && im->second_axis_legend[0] != '\0') {
Xvertical2 = im->text_prop[TEXT_PROP_UNIT].size * 2;
}
else{
Xvertical2 = Xspacing;
}
- if (im->title[0] != '\0') {
+ if (im->title && im->title[0] != '\0') {
/* The title is placed "inbetween" two text lines so it
** automatically has some vertical spacing. The horizontal
** spacing is added here, on each side.
Ymain -= 0.5*Yspacing;
}
- if (im->watermark[0] != '\0') {
+ if (im->watermark && im->watermark[0] != '\0') {
Ymain -= Ywatermark;
}
/* limit the remaining height to 0 */
im->yimg += 0.5*Yspacing;
}
- if (im->watermark[0] != '\0') {
+ if (im->watermark && im->watermark[0] != '\0') {
im->yimg += Ywatermark;
}
}
im->step = 0;
im->symbol = ' ';
im->tabwidth = 40.0;
- im->title[0] = '\0';
+ im->title = NULL;
im->unitsexponent = 9999;
im->unitslength = 6;
im->viewfactor = 1.0;
- im->watermark[0] = '\0';
+ im->watermark = NULL;
+ im->xlab_form = NULL;
im->with_markup = 0;
im->ximg = 0;
im->xlab_user.minsec = -1;
im->xsize = 400;
im->ygridstep = DNAN;
im->yimg = 0;
- im->ylegend[0] = '\0';
+ im->ylegend = NULL;
im->second_axis_scale = 0; /* 0 disables it */
im->second_axis_shift = 0; /* no shift by default */
- im->second_axis_legend[0] = '\0';
- im->second_axis_format[0] = '\0';
- im->primary_axis_format[0] = '\0';
+ im->second_axis_legend = NULL;
+ im->second_axis_format = NULL;
+ im->primary_axis_format = NULL;
im->yorigin = 0;
im->yOriginLegend = 0;
im->yOriginLegendY = 0;
scan_ltm,
&im->xlab_user.labst,
&im->xlab_user.precis, &stroff) == 7 && stroff != 0) {
- strncpy(im->xlab_form, optarg + stroff,
- sizeof(im->xlab_form) - 1);
- im->xlab_form[sizeof(im->xlab_form) - 1] = '\0';
+ im->xlab_form=strdup(optarg + stroff);
+ if (!im->xlab_form) {
+ rrd_set_error("cannot allocate memory for xlab_form");
+ return;
+ }
if ((int)
(im->xlab_user.gridtm = tmt_conv(scan_gtm)) == -1) {
rrd_set_error("unknown keyword %s", scan_gtm);
return;
}
im->xlab_user.minsec = 1;
- im->xlab_user.stst = im->xlab_form;
+ im->xlab_user.stst = im->xlab_form ? im->xlab_form : "";
} else {
rrd_set_error("invalid x-grid format");
return;
}
break;
case 1003:
- strncpy(im->second_axis_legend,optarg,150);
- im->second_axis_legend[150]='\0';
+ im->second_axis_legend=strdup(optarg);
+ if (!im->second_axis_legend) {
+ rrd_set_error("cannot allocate memory for second_axis_legend");
+ return;
+ }
break;
case 1004:
if (bad_format(optarg)){
rrd_set_error("use either %le or %lf formats");
return;
}
- strncpy(im->second_axis_format,optarg,150);
- im->second_axis_format[150]='\0';
+ im->second_axis_format=strdup(optarg);
+ if (!im->second_axis_format) {
+ rrd_set_error("cannot allocate memory for second_axis_format");
+ return;
+ }
break;
case 1012:
if (bad_format(optarg)){
rrd_set_error("use either %le or %lf formats");
return;
}
- strncpy(im->primary_axis_format,optarg,150);
- im->primary_axis_format[150]='\0';
+ im->primary_axis_format=strdup(optarg);
+ if (!im->primary_axis_format) {
+ rrd_set_error("cannot allocate memory for primary_axis_format");
+ return;
+ }
break;
case 'v':
- strncpy(im->ylegend, optarg, 150);
- im->ylegend[150] = '\0';
+ im->ylegend=strdup(optarg);
+ if (!im->ylegend) {
+ rrd_set_error("cannot allocate memory for ylegend");
+ return;
+ }
break;
case 'u':
im->maxval = atof(optarg);
}
break;
case 't':
- strncpy(im->title, optarg, 150);
- im->title[150] = '\0';
+ im->title=strdup(optarg);
+ if (!im->title) {
+ rrd_set_error("cannot allocate memory for title");
+ return;
+ }
break;
case 'R':
if (strcmp(optarg, "normal") == 0) {
/* not supported curently */
break;
case 'W':
- strncpy(im->watermark, optarg, 100);
- im->watermark[99] = '\0';
+ im->watermark=strdup(optarg);
+ if (!im->watermark) {
+ rrd_set_error("cannot allocate memory for watermark");
+ return;
+ }
break;
case 'd':
{
long xsize, ysize; /* graph area size in pixels */
struct gfx_color_t graph_col[__GRC_END__]; /* real colors for the graph */
text_prop_t text_prop[TEXT_PROP_LAST]; /* text properties */
- char ylegend[210]; /* legend along the yaxis */
- char title[210]; /* title for graph */
- char watermark[110]; /* watermark for graph */
+ char *ylegend; /* legend along the yaxis */
+ char *title; /* title for graph */
+ char *watermark; /* watermark for graph */
int draw_x_grid; /* no x-grid at all */
int draw_y_grid; /* no y-grid at all */
unsigned int draw_3d_border; /* size of border in pixels, 0 for off */
unsigned int dynamic_labels; /* pick the label shape according to the line drawn */
double grid_dash_on, grid_dash_off;
xlab_t xlab_user; /* user defined labeling for xaxis */
- char xlab_form[210]; /* format for the label on the xaxis */
+ char *xlab_form; /* format for the label on the xaxis */
double second_axis_scale; /* relative to the first axis (0 to disable) */
double second_axis_shift; /* how much is it shifted vs the first axis */
- char second_axis_legend[210]; /* label to put on the seond axis */
- char second_axis_format[210]; /* format for the numbers on the scond axis */
- char primary_axis_format[210]; /* format for the numbers on the primary axis */
+ char *second_axis_legend; /* label to put on the seond axis */
+ char *second_axis_format; /* format for the numbers on the scond axis */
+ char *primary_axis_format; /* format for the numbers on the primary axis */
double ygridstep; /* user defined step for y grid */
int ylabfact; /* every how many y grid shall a label be written ? */
double tabwidth; /* tabwdith */