Fossil SCM

Ensure the line buffer for the legacy comment printing algorithm can hold maximum-length UTF-8 sequences.

florian 2018-11-15 15:32 UTC comment-formatter-utf8
Commit 29d3a2ed4ee03c7f7ba222b7f2fddfa27c5cd823
1 file changed +3 -2
+3 -2
--- src/comformat.c
+++ src/comformat.c
@@ -322,12 +322,13 @@
322322
}
323323
if( zText==0 ) zText = "(NULL)";
324324
if( maxChars<=0 ){
325325
maxChars = strlen(zText);
326326
}
327
- if( maxChars >= (sizeof(zBuffer)) ){
328
- zBuf = fossil_malloc(maxChars+1);
327
+ /* Ensure the buffer can hold the longest-possible UTF-8 sequences. */
328
+ if( maxChars >= (sizeof(zBuffer)/4-1) ){
329
+ zBuf = fossil_malloc(maxChars*4+1);
329330
}else{
330331
zBuf = zBuffer;
331332
}
332333
for(;;){
333334
while( fossil_isspace(zText[0]) ){ zText++; }
334335
--- src/comformat.c
+++ src/comformat.c
@@ -322,12 +322,13 @@
322 }
323 if( zText==0 ) zText = "(NULL)";
324 if( maxChars<=0 ){
325 maxChars = strlen(zText);
326 }
327 if( maxChars >= (sizeof(zBuffer)) ){
328 zBuf = fossil_malloc(maxChars+1);
 
329 }else{
330 zBuf = zBuffer;
331 }
332 for(;;){
333 while( fossil_isspace(zText[0]) ){ zText++; }
334
--- src/comformat.c
+++ src/comformat.c
@@ -322,12 +322,13 @@
322 }
323 if( zText==0 ) zText = "(NULL)";
324 if( maxChars<=0 ){
325 maxChars = strlen(zText);
326 }
327 /* Ensure the buffer can hold the longest-possible UTF-8 sequences. */
328 if( maxChars >= (sizeof(zBuffer)/4-1) ){
329 zBuf = fossil_malloc(maxChars*4+1);
330 }else{
331 zBuf = zBuffer;
332 }
333 for(;;){
334 while( fossil_isspace(zText[0]) ){ zText++; }
335

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button