mirror of
https://github.com/libexpat/libexpat.git
synced 2025-04-04 21:04:57 +00:00
xmlwf: Address clang-tidy warning bugprone-narrowing-conversions
The symptom was: > [..]/expat/xmlwf/xmlfile.c:204:13: error: narrowing conversion from 'ssize_t' (aka 'long') to signed type 'int' is implementation-defined [bugprone-narrowing-conversions,-warnings-as-errors] > 204 | nread = read(fd, buf, g_read_size_bytes); > | ^ > [..]/expat/xmlwf/xmlwf.c:314:14: error: narrowing conversion from 'unsigned long' to signed type 'int' is implementation-defined [bugprone-narrowing-conversions,-warnings-as-errors] > 314 | numBytes = count * sizeof(XML_Char); > | ^ The solution to read(3) was copied from file xmlwf/readfilemap.c for now.
This commit is contained in:
parent
57a7643252
commit
0c5b205a01
2 changed files with 14 additions and 7 deletions
|
@ -56,12 +56,19 @@
|
|||
#include "xmltchar.h"
|
||||
#include "filemap.h"
|
||||
|
||||
/* Function "read": */
|
||||
#if defined(_MSC_VER)
|
||||
# include <io.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
/* https://msdn.microsoft.com/en-us/library/wyssk1bs(v=vs.100).aspx */
|
||||
# define EXPAT_read _read
|
||||
# define EXPAT_read_count_t int
|
||||
# define EXPAT_read_req_t unsigned int
|
||||
#else /* POSIX */
|
||||
# include <unistd.h>
|
||||
/* https://pubs.opengroup.org/onlinepubs/009695399/functions/read.html */
|
||||
# define EXPAT_read read
|
||||
# define EXPAT_read_count_t ssize_t
|
||||
# define EXPAT_read_req_t size_t
|
||||
#endif
|
||||
|
||||
#ifndef O_BINARY
|
||||
|
@ -192,7 +199,7 @@ processStream(const XML_Char *filename, XML_Parser parser) {
|
|||
}
|
||||
}
|
||||
for (;;) {
|
||||
int nread;
|
||||
EXPAT_read_count_t nread;
|
||||
char *buf = (char *)XML_GetBuffer(parser, g_read_size_bytes);
|
||||
if (! buf) {
|
||||
if (filename != NULL)
|
||||
|
@ -201,14 +208,14 @@ processStream(const XML_Char *filename, XML_Parser parser) {
|
|||
filename != NULL ? filename : T("xmlwf"));
|
||||
return 0;
|
||||
}
|
||||
nread = read(fd, buf, g_read_size_bytes);
|
||||
nread = EXPAT_read(fd, buf, (EXPAT_read_req_t)g_read_size_bytes);
|
||||
if (nread < 0) {
|
||||
tperror(filename != NULL ? filename : T("STDIN"));
|
||||
if (filename != NULL)
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
if (XML_ParseBuffer(parser, nread, nread == 0) == XML_STATUS_ERROR) {
|
||||
if (XML_ParseBuffer(parser, (int)nread, nread == 0) == XML_STATUS_ERROR) {
|
||||
reportError(parser, filename != NULL ? filename : T("STDIN"));
|
||||
if (filename != NULL)
|
||||
close(fd);
|
||||
|
|
|
@ -305,7 +305,7 @@ static XML_Char *
|
|||
xcsdup(const XML_Char *s) {
|
||||
XML_Char *result;
|
||||
int count = 0;
|
||||
int numBytes;
|
||||
size_t numBytes;
|
||||
|
||||
/* Get the length of the string, including terminator */
|
||||
while (s[count++] != 0) {
|
||||
|
|
Loading…
Add table
Reference in a new issue