From adeffd47ec50cf2fbc5bdf5dd56caaa7bf43d90b Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Mon, 22 Aug 2011 18:08:02 +1000 Subject: [PATCH] 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 --- extract.c | 8 ++++---- load.c | 6 ++++-- split.c | 4 ++-- wiggle.h | 2 ++ 4 files changed, 12 insertions(+), 8 deletions(-) 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