gnucash maint: Bug 798740 - Build fails with gcc 13
John Ralls
jralls at code.gnucash.org
Mon Jan 30 19:51:13 EST 2023
Updated via https://github.com/Gnucash/gnucash/commit/ce3447e6 (commit)
from https://github.com/Gnucash/gnucash/commit/8a167d18 (commit)
commit ce3447e6ea8b2f734b24a2502e865ebbbc21aaaa
Author: John Ralls <jralls at ceridwen.us>
Date: Mon Jan 30 10:23:05 2023 -0800
Bug 798740 - Build fails with gcc 13
Protect against passing an lseek failure rv to read().
diff --git a/libgnucash/app-utils/file-utils.c b/libgnucash/app-utils/file-utils.c
index b8d464cfd..f61e21f5b 100644
--- a/libgnucash/app-utils/file-utils.c
+++ b/libgnucash/app-utils/file-utils.c
@@ -62,7 +62,7 @@ gncReadFile (const char * filename, char ** data)
{
char *buf = NULL;
char *fullname;
- int size = 0;
+ off_t size = 0;
int fd;
if (!filename || filename[0] == '\0') return 0;
@@ -89,18 +89,25 @@ gncReadFile (const char * filename, char ** data)
size = lseek( fd, 0, SEEK_END );
lseek( fd, 0, SEEK_SET );
+ if (size < 0)
+ {
+ int norr = errno;
+ PERR ("file seek-to-end %s: (%d) %s\n", filename, norr, strerror(norr));
+ return 0;
+ }
+
/* Allocate memory */
- buf = g_new(char, size + 1);
+ buf = g_new(char, (size_t)size + 1);
/* read in file */
- if ( read(fd, buf, size) == -1 )
+ if ( read(fd, buf, (size_t)size) == -1 )
{
g_free(buf);
buf = NULL;
}
else
{
- buf[size] = '\0';
+ buf[(size_t)size] = '\0';
}
close(fd);
Summary of changes:
libgnucash/app-utils/file-utils.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
More information about the gnucash-changes
mailing list