Overview
SHA1 Hash: | e44d7a4b5af0b66bf493ae55f0c8b71dc6ad46ed |
---|---|
Date: | 2008-10-26 02:29:22 |
User: | drh |
Comment: | Prevent buffer overrun when adding \r characters to the check-in
descriptions for win32. Ticket |
Timelines: | ancestors | descendants | both | trunk |
Other Links: | files | ZIP archive | manifest |
Tags And Properties
- branch=trunk inherited from [a28c83647d]
- sym-trunk inherited from [a28c83647d]
Changes
[hide diffs]Modified src/blob.c from [ea84a9c14c] to [2492695b87].
@@ -836,35 +836,35 @@ blob_reset(&b3); } printf("ok\n"); } +#ifdef __MINGW32__ /* ** Convert every \n character in the given blob into \r\n. */ void blob_add_cr(Blob *p){ - int i, j, n; char *z = p->aData; - for(i=n=0; i<p->nUsed; i++){ + int j = p->nUsed; + int i, n; + for(i=n=0; i<j; i++){ if( z[i]=='\n' ) n++; } - if( p->nUsed+n+1>p->nAlloc ){ - blob_resize(p, p->nUsed+n); + j += n; + if( j>=p->nAlloc ){ + blob_resize(p, j); z = p->aData; } - i = p->nUsed - 1; - j = i + n; + p->nUsed = j; + z[j] = 0; while( j>i ){ - z[j--] = z[i]; - if( z[i]=='\n' ){ - z[j--] = '\r'; + if( (z[--j] = z[--i]) =='\n' ){ + z[--j] = '\r'; } - i--; } - p->nUsed += n; - p->aData[p->nUsed] = 0; } +#endif /* ** Remove every \r character from the given blob. */ void blob_remove_cr(Blob *p){