From: Neil Brown Date: Mon, 22 Aug 2011 08:08:02 +0000 (+1000) Subject: nul terminate stream read from a file. X-Git-Tag: v0.9~68 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=adeffd47ec50cf2fbc5bdf5dd56caaa7bf43d90b;p=wiggle.git nul terminate stream read from a file. Though we carry around the length of a string and so will not normally need a nul terminator, we sometimes use sscanf which cannot take a length and so needs nul termination. So add a nul when loading from a file or stdin. Signed-off-by: NeilBrown --- diff --git a/extract.c b/extract.c index 92d50a3..ce40310 100644 --- a/extract.c +++ b/extract.c @@ -118,15 +118,15 @@ int split_patch(struct stream f, struct stream *f1, struct stream *f2) buf[0] = 0; chunks++; sprintf(buf+1, "%5d %5d %5d\n", chunks, a, acnt); - memcpy(r1.body+r1.len, buf, 19); - r1.len += 19; + memcpy(r1.body+r1.len, buf, 20); + r1.len += 20; } if (state==2 || state == 3) { char buf[20]; buf[0] = 0; sprintf(buf+1, "%5d %5d %5d\n", chunks, c, bcnt); - memcpy(r2.body+r2.len, buf, 19); - r2.len += 19; + memcpy(r2.body+r2.len, buf, 20); + r2.len += 20; } break; case 1: diff --git a/load.c b/load.c index 23e4e24..b544169 100644 --- a/load.c +++ b/load.c @@ -52,7 +52,7 @@ static void join_streams(struct stream list[], int cnt) for (i=0; i