[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * info/filesys.c (filesys_read_info_file): conver
From: |
Patrice Dumas |
Subject: |
branch master updated: * info/filesys.c (filesys_read_info_file): convert to ssize_t to use as read return value an not to size_t and convert to size_t later on. Do not cast finfo->st_size to (long), leave it as off_t and convert to either size_t or ssize_t depending on how the file is read. Add comments to mark conversion from unsigned to signed. |
Date: |
Thu, 10 Oct 2024 05:56:34 -0400 |
This is an automated email from the git hooks/post-receive script.
pertusus pushed a commit to branch master
in repository texinfo.
The following commit(s) were added to refs/heads/master by this push:
new bfe415e591 * info/filesys.c (filesys_read_info_file): convert to
ssize_t to use as read return value an not to size_t and convert to size_t
later on. Do not cast finfo->st_size to (long), leave it as off_t and convert
to either size_t or ssize_t depending on how the file is read. Add comments to
mark conversion from unsigned to signed.
bfe415e591 is described below
commit bfe415e591189d082a7765896dac5ea692e5de66
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Thu Oct 10 11:56:24 2024 +0200
* info/filesys.c (filesys_read_info_file): convert to ssize_t to use
as read return value an not to size_t and convert to size_t later on.
Do not cast finfo->st_size to (long), leave it as off_t and convert to
either size_t or ssize_t depending on how the file is read. Add
comments to mark conversion from unsigned to signed.
* info/filesys.c (convert_eols): use size_t in argument an as return
type.
---
ChangeLog | 11 +++++++++++
info/filesys.c | 33 ++++++++++++++++++++-------------
2 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 3756334bfb..67305dc4cb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2024-10-10 Patrice Dumas <pertusus@free.fr>
+
+ * info/filesys.c (filesys_read_info_file): convert to ssize_t to use
+ as read return value an not to size_t and convert to size_t later on.
+ Do not cast finfo->st_size to (long), leave it as off_t and convert to
+ either size_t or ssize_t depending on how the file is read. Add
+ comments to mark conversion from unsigned to signed.
+
+ * info/filesys.c (convert_eols): use size_t in argument an as return
+ type.
+
2024-10-10 Patrice Dumas <pertusus@free.fr>
* info/window.h (LINE_MAP): use long for nline field to be consistent
diff --git a/info/filesys.c b/info/filesys.c
index d4db6cb9dd..44fc67882b 100644
--- a/info/filesys.c
+++ b/info/filesys.c
@@ -281,8 +281,8 @@ info_add_extension (char *dirname, char *filename, struct
stat *finfo)
a single newline at each EOL; in particular, searching for various
Info headers and cookies can become extremely tricky if that assumption
breaks. */
-static long
-convert_eols (char *text, long int textlen)
+static size_t
+convert_eols (char *text, size_t textlen)
{
register char *s = text;
register char *d = text;
@@ -310,22 +310,27 @@ char *
filesys_read_info_file (char *pathname, size_t *filesize,
struct stat *finfo, int *is_compressed)
{
- size_t fsize;
+ off_t stat_fsize;
+ size_t file_size;
char *contents;
- fsize = filesys_error_number = 0;
+ filesys_error_number = 0;
stat (pathname, finfo);
- fsize = (long) finfo->st_size;
+ stat_fsize = finfo->st_size;
if (compressed_filename_p (pathname))
{
+ /* NOTE convert positive unsigned off_t to size_t */
+ file_size = stat_fsize;
*is_compressed = 1;
- contents = filesys_read_compressed (pathname, &fsize);
+
+ contents = filesys_read_compressed (pathname, &file_size);
}
else
{
int descriptor;
+ ssize_t read_file_size = stat_fsize;
*is_compressed = 0;
descriptor = open (pathname, O_RDONLY | O_BINARY, 0666);
@@ -338,16 +343,18 @@ filesys_read_info_file (char *pathname, size_t *filesize,
}
/* Try to read the contents of this file. */
- contents = xmalloc (1 + fsize);
- if ((read (descriptor, contents, fsize)) != fsize)
+ contents = xmalloc (1 + read_file_size);
+ if ((read (descriptor, contents, read_file_size)) != read_file_size)
{
filesys_error_number = errno;
close (descriptor);
free (contents);
return NULL;
}
- contents[fsize] = 0;
+ contents[read_file_size] = 0;
close (descriptor);
+ /* NOTE convert positive unsigned ssize_t to size_t */
+ file_size = read_file_size;
}
#if defined (__MSDOS__) || defined (__MINGW32__)
@@ -364,15 +371,15 @@ filesys_read_info_file (char *pathname, size_t *filesize,
Also, this will allow any Info files that contain any CR-LF endings by
mistake to work as expected (except on MS-DOS/Windows). */
- fsize = convert_eols (contents, fsize);
+ file_size = convert_eols (contents, file_size);
/* EOL conversion can shrink the text quite a bit. We don't
want to waste storage. */
- contents = xrealloc (contents, 1 + fsize);
- contents[fsize] = '\0';
+ contents = xrealloc (contents, 1 + file_size);
+ contents[file_size] = '\0';
#endif
- *filesize = fsize;
+ *filesize = file_size;
return contents;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * info/filesys.c (filesys_read_info_file): convert to ssize_t to use as read return value an not to size_t and convert to size_t later on. Do not cast finfo->st_size to (long), leave it as off_t and convert to either size_t or ssize_t depending on how the file is read. Add comments to mark conversion from unsigned to signed.,
Patrice Dumas <=