From f7613e2b9a4c5ce0c2a1807a9604b8df609124f4 Mon Sep 17 00:00:00 2001 From: oetiker Date: Thu, 5 May 2005 09:07:56 +0000 Subject: [PATCH] better not to write into argv elements ... Henrik Stoerner git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2@484 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/src/rrd_create.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/program/src/rrd_create.c b/program/src/rrd_create.c index 1807dcab..69ed8d87 100644 --- a/program/src/rrd_create.c +++ b/program/src/rrd_create.c @@ -183,7 +183,8 @@ rrd_create_r(char *filename, return -1; } rrd.stat_head -> ds_cnt++; - } else if (strncmp(argv[i],"RRA:",3)==0){ + } else if (strncmp(argv[i],"RRA:",4)==0){ + char *argvcopy; char *tokptr; size_t old_size = sizeof(rra_def_t)*(rrd.stat_head->rra_cnt); if((rrd.rra_def = rrd_realloc(rrd.rra_def, @@ -194,8 +195,9 @@ rrd_create_r(char *filename, return(-1); } memset(&rrd.rra_def[rrd.stat_head->rra_cnt], 0, sizeof(rra_def_t)); - - token = strtok_r(&argv[i][4],":", &tokptr); + + argvcopy = strdup(argv[i]); + token = strtok_r(&argvcopy[4],":", &tokptr); token_idx = error_flag = 0; while (token != NULL) { @@ -370,12 +372,14 @@ rrd_create_r(char *filename, if (rrd_test_error()) { /* all errors are unrecoverable */ + free(argvcopy); rrd_free(&rrd); return (-1); } token = strtok_r(NULL,":", &tokptr); token_idx++; } /* end while */ + free(argvcopy); #ifdef DEBUG fprintf(stderr,"Creating RRA CF: %s, dep idx %lu, current idx %lu\n", rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam, -- 2.30.2