X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcommon%2Fstrbuf.c;h=320e912932ac86ca1c9a15979a522a22e38cc98e;hb=0d8e8a95338560a1e0d96258d6def311cf2ad368;hp=4a489a708fb3887ae0968eb4cd221d9825c12fe8;hpb=9174f65e541b4e1008d40ff2b86db849b2086065;p=cc65 diff --git a/src/common/strbuf.c b/src/common/strbuf.c index 4a489a708..320e91293 100644 --- a/src/common/strbuf.c +++ b/src/common/strbuf.c @@ -179,7 +179,7 @@ static void SB_CheapRealloc (StrBuf* B, unsigned NewSize) /* Allocate a fresh block */ B->Buf = xmalloc (NewAllocated); - + /* Remember the new block size */ B->Allocated = NewAllocated; } @@ -225,11 +225,13 @@ void SB_Terminate (StrBuf* B) void SB_CopyBuf (StrBuf* Target, const char* Buf, unsigned Size) /* Copy Buf to Target, discarding the old contents of Target */ -{ - if (Target->Allocated < Size) { - SB_CheapRealloc (Target, Size); +{ + if (Size) { + if (Target->Allocated < Size) { + SB_CheapRealloc (Target, Size); + } + memcpy (Target->Buf, Buf, Size); } - memcpy (Target->Buf, Buf, Size); Target->Len = Size; }