Fossil SCM

Merge the blob_write_to_file() fix into small-fixes-2 after the merge of trunk, so that the branch has one leaf.

dmestas 2026-11-17 13:10 UTC small-fixes-2 merge
Commit bda4a75290b313e50a8fe747579613939c03f085ff6115cf31ee9b5454945de1
2 files changed +6 -2 +6 -2
+6 -2
--- src/blob.c
+++ src/blob.c
@@ -1335,11 +1335,14 @@
13351335
nWrote = fossil_utf8_to_console(blob_buffer(pBlob), blob_size(pBlob), 0);
13361336
if( nWrote>=0 ) return nWrote;
13371337
fflush(stdout);
13381338
_setmode(_fileno(stdout), _O_BINARY);
13391339
#endif
1340
- nWrote = fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), stdout);
1340
+ /* A blob of no bytes can have no buffer, and fwrite() is not to be
1341
+ ** given a null pointer. */
1342
+ nWrote = blob_size(pBlob)>0
1343
+ ? fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), stdout) : 0;
13411344
#if defined(_WIN32)
13421345
fflush(stdout);
13431346
_setmode(_fileno(stdout), _O_TEXT);
13441347
#endif
13451348
}else{
@@ -1356,11 +1359,12 @@
13561359
fossil_fatal_recursive("unable to open file \"%s\" for writing",
13571360
zFilename);
13581361
return 0;
13591362
}
13601363
blob_is_init(pBlob);
1361
- nWrote = fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), out);
1364
+ nWrote = blob_size(pBlob)>0
1365
+ ? fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), out) : 0;
13621366
fclose(out);
13631367
if( nWrote!=(int)blob_size(pBlob) ){
13641368
fossil_fatal_recursive("short write: %d of %d bytes to %s", nWrote,
13651369
blob_size(pBlob), zFilename);
13661370
}
13671371
--- src/blob.c
+++ src/blob.c
@@ -1335,11 +1335,14 @@
1335 nWrote = fossil_utf8_to_console(blob_buffer(pBlob), blob_size(pBlob), 0);
1336 if( nWrote>=0 ) return nWrote;
1337 fflush(stdout);
1338 _setmode(_fileno(stdout), _O_BINARY);
1339 #endif
1340 nWrote = fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), stdout);
 
 
 
1341 #if defined(_WIN32)
1342 fflush(stdout);
1343 _setmode(_fileno(stdout), _O_TEXT);
1344 #endif
1345 }else{
@@ -1356,11 +1359,12 @@
1356 fossil_fatal_recursive("unable to open file \"%s\" for writing",
1357 zFilename);
1358 return 0;
1359 }
1360 blob_is_init(pBlob);
1361 nWrote = fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), out);
 
1362 fclose(out);
1363 if( nWrote!=(int)blob_size(pBlob) ){
1364 fossil_fatal_recursive("short write: %d of %d bytes to %s", nWrote,
1365 blob_size(pBlob), zFilename);
1366 }
1367
--- src/blob.c
+++ src/blob.c
@@ -1335,11 +1335,14 @@
1335 nWrote = fossil_utf8_to_console(blob_buffer(pBlob), blob_size(pBlob), 0);
1336 if( nWrote>=0 ) return nWrote;
1337 fflush(stdout);
1338 _setmode(_fileno(stdout), _O_BINARY);
1339 #endif
1340 /* A blob of no bytes can have no buffer, and fwrite() is not to be
1341 ** given a null pointer. */
1342 nWrote = blob_size(pBlob)>0
1343 ? fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), stdout) : 0;
1344 #if defined(_WIN32)
1345 fflush(stdout);
1346 _setmode(_fileno(stdout), _O_TEXT);
1347 #endif
1348 }else{
@@ -1356,11 +1359,12 @@
1359 fossil_fatal_recursive("unable to open file \"%s\" for writing",
1360 zFilename);
1361 return 0;
1362 }
1363 blob_is_init(pBlob);
1364 nWrote = blob_size(pBlob)>0
1365 ? fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), out) : 0;
1366 fclose(out);
1367 if( nWrote!=(int)blob_size(pBlob) ){
1368 fossil_fatal_recursive("short write: %d of %d bytes to %s", nWrote,
1369 blob_size(pBlob), zFilename);
1370 }
1371
+6 -2
--- src/blob.c
+++ src/blob.c
@@ -1335,11 +1335,14 @@
13351335
nWrote = fossil_utf8_to_console(blob_buffer(pBlob), blob_size(pBlob), 0);
13361336
if( nWrote>=0 ) return nWrote;
13371337
fflush(stdout);
13381338
_setmode(_fileno(stdout), _O_BINARY);
13391339
#endif
1340
- nWrote = fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), stdout);
1340
+ /* A blob of no bytes can have no buffer, and fwrite() is not to be
1341
+ ** given a null pointer. */
1342
+ nWrote = blob_size(pBlob)>0
1343
+ ? fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), stdout) : 0;
13411344
#if defined(_WIN32)
13421345
fflush(stdout);
13431346
_setmode(_fileno(stdout), _O_TEXT);
13441347
#endif
13451348
}else{
@@ -1356,11 +1359,12 @@
13561359
fossil_fatal_recursive("unable to open file \"%s\" for writing",
13571360
zFilename);
13581361
return 0;
13591362
}
13601363
blob_is_init(pBlob);
1361
- nWrote = fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), out);
1364
+ nWrote = blob_size(pBlob)>0
1365
+ ? fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), out) : 0;
13621366
fclose(out);
13631367
if( nWrote!=(int)blob_size(pBlob) ){
13641368
fossil_fatal_recursive("short write: %d of %d bytes to %s", nWrote,
13651369
blob_size(pBlob), zFilename);
13661370
}
13671371
--- src/blob.c
+++ src/blob.c
@@ -1335,11 +1335,14 @@
1335 nWrote = fossil_utf8_to_console(blob_buffer(pBlob), blob_size(pBlob), 0);
1336 if( nWrote>=0 ) return nWrote;
1337 fflush(stdout);
1338 _setmode(_fileno(stdout), _O_BINARY);
1339 #endif
1340 nWrote = fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), stdout);
 
 
 
1341 #if defined(_WIN32)
1342 fflush(stdout);
1343 _setmode(_fileno(stdout), _O_TEXT);
1344 #endif
1345 }else{
@@ -1356,11 +1359,12 @@
1356 fossil_fatal_recursive("unable to open file \"%s\" for writing",
1357 zFilename);
1358 return 0;
1359 }
1360 blob_is_init(pBlob);
1361 nWrote = fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), out);
 
1362 fclose(out);
1363 if( nWrote!=(int)blob_size(pBlob) ){
1364 fossil_fatal_recursive("short write: %d of %d bytes to %s", nWrote,
1365 blob_size(pBlob), zFilename);
1366 }
1367
--- src/blob.c
+++ src/blob.c
@@ -1335,11 +1335,14 @@
1335 nWrote = fossil_utf8_to_console(blob_buffer(pBlob), blob_size(pBlob), 0);
1336 if( nWrote>=0 ) return nWrote;
1337 fflush(stdout);
1338 _setmode(_fileno(stdout), _O_BINARY);
1339 #endif
1340 /* A blob of no bytes can have no buffer, and fwrite() is not to be
1341 ** given a null pointer. */
1342 nWrote = blob_size(pBlob)>0
1343 ? fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), stdout) : 0;
1344 #if defined(_WIN32)
1345 fflush(stdout);
1346 _setmode(_fileno(stdout), _O_TEXT);
1347 #endif
1348 }else{
@@ -1356,11 +1359,12 @@
1359 fossil_fatal_recursive("unable to open file \"%s\" for writing",
1360 zFilename);
1361 return 0;
1362 }
1363 blob_is_init(pBlob);
1364 nWrote = blob_size(pBlob)>0
1365 ? fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), out) : 0;
1366 fclose(out);
1367 if( nWrote!=(int)blob_size(pBlob) ){
1368 fossil_fatal_recursive("short write: %d of %d bytes to %s", nWrote,
1369 blob_size(pBlob), zFilename);
1370 }
1371

Keyboard Shortcuts

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