diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-04-19 23:18:35 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-04-19 23:18:35 +0000 |
commit | 4a11e0fb459a85d8c3930be680a5ee3f7839098a (patch) | |
tree | b3df84c830ad249467cbb93cc0ebeda085f392f4 | |
parent | 2894266f12e699570d223d9f19ca79979196060b (diff) | |
download | busybox-w32-4a11e0fb459a85d8c3930be680a5ee3f7839098a.tar.gz busybox-w32-4a11e0fb459a85d8c3930be680a5ee3f7839098a.tar.bz2 busybox-w32-4a11e0fb459a85d8c3930be680a5ee3f7839098a.zip |
Patch from David Updegraff to use calloc so that forward pointers start out
NULL, and so it can handle format strings that have stuff _after_ the last %?
specification
-rw-r--r-- | libbb/dump.c | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/libbb/dump.c b/libbb/dump.c index 26dabe57f..03ab9f315 100644 --- a/libbb/dump.c +++ b/libbb/dump.c | |||
@@ -96,7 +96,7 @@ static void rewrite(FS * fs) | |||
96 | enum { NOTOKAY, USEBCNT, USEPREC } sokay; | 96 | enum { NOTOKAY, USEBCNT, USEPREC } sokay; |
97 | register PR *pr, **nextpr = NULL; | 97 | register PR *pr, **nextpr = NULL; |
98 | register FU *fu; | 98 | register FU *fu; |
99 | register char *p1, *p2; | 99 | register char *p1, *p2, *p3; |
100 | char savech, *fmtp; | 100 | char savech, *fmtp; |
101 | const char *byte_count_str; | 101 | const char *byte_count_str; |
102 | int nconv, prec = 0; | 102 | int nconv, prec = 0; |
@@ -108,11 +108,13 @@ static void rewrite(FS * fs) | |||
108 | */ | 108 | */ |
109 | for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) { | 109 | for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) { |
110 | /* NOSTRICT */ | 110 | /* NOSTRICT */ |
111 | pr = (PR *) xmalloc(sizeof(PR)); | 111 | /* DBU:[dvae@cray.com] calloc so that forward ptrs start out NULL*/ |
112 | pr = (PR *) xcalloc(1,sizeof(PR)); | ||
112 | if (!fu->nextpr) | 113 | if (!fu->nextpr) |
113 | fu->nextpr = pr; | 114 | fu->nextpr = pr; |
114 | else | 115 | /* ignore nextpr -- its unused inside the loop and is |
115 | *nextpr = pr; | 116 | * uninitialized 1st time thru. |
117 | */ | ||
116 | 118 | ||
117 | /* bb_dump_skip preceding text and up to the next % sign */ | 119 | /* bb_dump_skip preceding text and up to the next % sign */ |
118 | for (p1 = fmtp; *p1 && *p1 != '%'; ++p1); | 120 | for (p1 = fmtp; *p1 && *p1 != '%'; ++p1); |
@@ -244,6 +246,24 @@ static void rewrite(FS * fs) | |||
244 | pr->fmt = bb_xstrdup(fmtp); | 246 | pr->fmt = bb_xstrdup(fmtp); |
245 | *p2 = savech; | 247 | *p2 = savech; |
246 | pr->cchar = pr->fmt + (p1 - fmtp); | 248 | pr->cchar = pr->fmt + (p1 - fmtp); |
249 | |||
250 | /* DBU:[dave@cray.com] w/o this, trailing fmt text, space is lost. | ||
251 | * Skip subsequent text and up to the next % sign and tack the | ||
252 | * additional text onto fmt: eg. if fmt is "%x is a HEX number", | ||
253 | * we lose the " is a HEX number" part of fmt. | ||
254 | */ | ||
255 | for (p3 = p2; *p3 && *p3 != '%'; p3++); | ||
256 | if (p3 > p2) | ||
257 | { | ||
258 | savech = *p3; | ||
259 | *p3 = '\0'; | ||
260 | if (!(pr->fmt = realloc(pr->fmt, strlen(pr->fmt)+(p3-p2)+1))) | ||
261 | perror_msg_and_die("hexdump"); | ||
262 | strcat(pr->fmt, p2); | ||
263 | *p3 = savech; | ||
264 | p2 = p3; | ||
265 | } | ||
266 | |||
247 | fmtp = p2; | 267 | fmtp = p2; |
248 | 268 | ||
249 | /* only one conversion character if byte count */ | 269 | /* only one conversion character if byte count */ |
@@ -346,12 +366,13 @@ static int next(char **argv) | |||
346 | static u_char *get(void) | 366 | static u_char *get(void) |
347 | { | 367 | { |
348 | static int ateof = 1; | 368 | static int ateof = 1; |
349 | static u_char *curp, *savp; | 369 | static u_char *curp=NULL, *savp; /*DBU:[dave@cray.com]initialize curp */ |
350 | register int n; | 370 | register int n; |
351 | int need, nread; | 371 | int need, nread; |
352 | u_char *tmpp; | 372 | u_char *tmpp; |
353 | 373 | ||
354 | if (!curp) { | 374 | if (!curp) { |
375 | address = (off_t)0; /*DBU:[dave@cray.com] initialize,initialize..*/ | ||
355 | curp = (u_char *) xmalloc(bb_dump_blocksize); | 376 | curp = (u_char *) xmalloc(bb_dump_blocksize); |
356 | savp = (u_char *) xmalloc(bb_dump_blocksize); | 377 | savp = (u_char *) xmalloc(bb_dump_blocksize); |
357 | } else { | 378 | } else { |
@@ -673,7 +694,7 @@ void bb_dump_add(const char *fmt) | |||
673 | 694 | ||
674 | /* start new linked list of format units */ | 695 | /* start new linked list of format units */ |
675 | /* NOSTRICT */ | 696 | /* NOSTRICT */ |
676 | tfs = (FS *) xmalloc(sizeof(FS)); | 697 | tfs = (FS *) xcalloc(1,sizeof(FS)); /*DBU:[dave@cray.com] start out NULL */ |
677 | if (!bb_dump_fshead) { | 698 | if (!bb_dump_fshead) { |
678 | bb_dump_fshead = tfs; | 699 | bb_dump_fshead = tfs; |
679 | } else { | 700 | } else { |
@@ -692,7 +713,8 @@ void bb_dump_add(const char *fmt) | |||
692 | 713 | ||
693 | /* allocate a new format unit and link it in */ | 714 | /* allocate a new format unit and link it in */ |
694 | /* NOSTRICT */ | 715 | /* NOSTRICT */ |
695 | tfu = (FU *) xmalloc(sizeof(FU)); | 716 | /* DBU:[dave@cray.com] calloc so that forward pointers start out NULL */ |
717 | tfu = (FU *) xcalloc(1,sizeof(FU)); | ||
696 | *nextfu = tfu; | 718 | *nextfu = tfu; |
697 | nextfu = &tfu->nextfu; | 719 | nextfu = &tfu->nextfu; |
698 | tfu->reps = 1; | 720 | tfu->reps = 1; |