[BusyBox-cvs] busybox/libbb dump.c,1.4,1.5

Erik Andersen andersen at codepoet.org
Sat Apr 19 23:18:39 UTC 2003


Update of /var/cvs/busybox/libbb
In directory winder:/tmp/cvs-serv24039/libbb

Modified Files:
	dump.c 
Log Message:
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


Index: dump.c
===================================================================
RCS file: /var/cvs/busybox/libbb/dump.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- dump.c	19 Mar 2003 09:12:06 -0000	1.4
+++ dump.c	19 Apr 2003 23:18:35 -0000	1.5
@@ -96,7 +96,7 @@
 	enum { NOTOKAY, USEBCNT, USEPREC } sokay;
 	register PR *pr, **nextpr = NULL;
 	register FU *fu;
-	register char *p1, *p2;
+	register char *p1, *p2, *p3;
 	char savech, *fmtp;
 	const char *byte_count_str;
 	int nconv, prec = 0;
@@ -108,11 +108,13 @@
 		 */
 		for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) {
 			/* NOSTRICT */
-			pr = (PR *) xmalloc(sizeof(PR));
+			/* DBU:[dvae at cray.com] calloc so that forward ptrs start out NULL*/
+			pr = (PR *) xcalloc(1,sizeof(PR));
 			if (!fu->nextpr)
 				fu->nextpr = pr;
-			else
-				*nextpr = pr;
+			/* ignore nextpr -- its unused inside the loop and is
+			 * uninitialized 1st time thru.
+			 */
 
 			/* bb_dump_skip preceding text and up to the next % sign */
 			for (p1 = fmtp; *p1 && *p1 != '%'; ++p1);
@@ -244,6 +246,24 @@
 			pr->fmt = bb_xstrdup(fmtp);
 			*p2 = savech;
 			pr->cchar = pr->fmt + (p1 - fmtp);
+
+			/* DBU:[dave at cray.com] w/o this, trailing fmt text, space is lost.
+			 * Skip subsequent text and up to the next % sign and tack the 
+			 * additional text onto fmt: eg. if fmt is "%x is a HEX number", 
+			 * we lose the " is a HEX number" part of fmt.
+			 */
+			for (p3 = p2; *p3 && *p3 != '%'; p3++);
+			if (p3 > p2)
+			{
+				savech = *p3;
+				*p3 = '\0';
+				if (!(pr->fmt = realloc(pr->fmt, strlen(pr->fmt)+(p3-p2)+1)))
+					perror_msg_and_die("hexdump");
+				strcat(pr->fmt, p2);
+				*p3 = savech;
+				p2 = p3;
+			}
+
 			fmtp = p2;
 
 			/* only one conversion character if byte count */
@@ -346,12 +366,13 @@
 static u_char *get(void)
 {
 	static int ateof = 1;
-	static u_char *curp, *savp;
+	static u_char *curp=NULL, *savp; /*DBU:[dave at cray.com]initialize curp */
 	register int n;
 	int need, nread;
 	u_char *tmpp;
 
 	if (!curp) {
+		address = (off_t)0; /*DBU:[dave at cray.com] initialize,initialize..*/
 		curp = (u_char *) xmalloc(bb_dump_blocksize);
 		savp = (u_char *) xmalloc(bb_dump_blocksize);
 	} else {
@@ -673,7 +694,7 @@
 
 	/* start new linked list of format units */
 	/* NOSTRICT */
-	tfs = (FS *) xmalloc(sizeof(FS));
+ 	tfs = (FS *) xcalloc(1,sizeof(FS)); /*DBU:[dave at cray.com] start out NULL */
 	if (!bb_dump_fshead) {
 		bb_dump_fshead = tfs;
 	} else {
@@ -692,7 +713,8 @@
 
 		/* allocate a new format unit and link it in */
 		/* NOSTRICT */
-		tfu = (FU *) xmalloc(sizeof(FU));
+		/* DBU:[dave at cray.com] calloc so that forward pointers start out NULL */
+		tfu = (FU *) xcalloc(1,sizeof(FU));
 		*nextfu = tfu;
 		nextfu = &tfu->nextfu;
 		tfu->reps = 1;



More information about the busybox-cvs mailing list