|
From: <sv...@va...> - 2014-08-24 22:00:59
|
Author: florian
Date: Sun Aug 24 22:00:47 2014
New Revision: 14356
Log:
Automatically grow the buffer when it becomes full.
Telling the user to increase the buffer size manually
and recompile is so seventies.
Modified:
branches/BUF_REMOVAL/cachegrind/cg_merge.c
Modified: branches/BUF_REMOVAL/cachegrind/cg_merge.c
==============================================================================
--- branches/BUF_REMOVAL/cachegrind/cg_merge.c (original)
+++ branches/BUF_REMOVAL/cachegrind/cg_merge.c Sun Aug 24 22:00:47 2014
@@ -479,18 +479,24 @@
static
Counts* splitUpCountsLine ( SOURCE* s, /*OUT*/UWord* lnno, char* str )
{
-#define N_TMPC 50
Bool ok;
Counts* counts;
- ULong tmpC[N_TMPC];
- Int n_tmpC = 0;
+ Int n_tmpC = 0, tmpCsize = 50;
+ ULong *tmpC = malloc(tmpCsize * sizeof *tmpC);
+ if (tmpC == NULL)
+ mallocFail(s, "splitUpCountsLine:");
+
while (1) {
ok = parse_ULong( &tmpC[n_tmpC], &str );
if (!ok)
break;
n_tmpC++;
- if (n_tmpC >= N_TMPC)
- barf(s, "N_TMPC too low. Increase and recompile.");
+ if (n_tmpC >= tmpCsize) {
+ tmpCsize += 50;
+ tmpC = realloc(tmpC, tmpCsize * sizeof *tmpC);
+ if (tmpC == NULL)
+ mallocFail(s, "splitUpCountsLine:");
+ }
}
if (*str != 0)
parseError(s, "garbage in counts line");
@@ -503,9 +509,9 @@
} else {
counts = new_Counts( n_tmpC, /*COPIED*/&tmpC[0] );
}
+ free(tmpC);
return counts;
-#undef N_TMPC
}
static void addCounts ( SOURCE* s, /*OUT*/Counts* counts1, Counts* counts2 )
|