Differences From:
File
src/blob.c
part of check-in
[e976aa6fcb]
- Use cr/nl instead of just nl at the end of every line on the check-in comment
template for windows. Strip out the cr characters before completing the
commit.
by
drh on
2008-06-08 19:31:28.
[view]
To:
File
src/blob.c
part of check-in
[e44d7a4b5a]
- Prevent buffer overrun when adding \r characters to the check-in
descriptions for win32. Ticket 41bb23e650.
by
drh on
2008-10-26 02:29:22.
[view]
@@ -837,33 +837,33 @@
}
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.
*/