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 "xmltchar.h"
|
||||||
#include "filemap.h"
|
#include "filemap.h"
|
||||||
|
|
||||||
|
/* Function "read": */
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
# include <io.h>
|
# include <io.h>
|
||||||
#endif
|
/* https://msdn.microsoft.com/en-us/library/wyssk1bs(v=vs.100).aspx */
|
||||||
|
# define EXPAT_read _read
|
||||||
#ifdef HAVE_UNISTD_H
|
# define EXPAT_read_count_t int
|
||||||
|
# define EXPAT_read_req_t unsigned int
|
||||||
|
#else /* POSIX */
|
||||||
# include <unistd.h>
|
# 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
|
#endif
|
||||||
|
|
||||||
#ifndef O_BINARY
|
#ifndef O_BINARY
|
||||||
|
@ -192,7 +199,7 @@ processStream(const XML_Char *filename, XML_Parser parser) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int nread;
|
EXPAT_read_count_t nread;
|
||||||
char *buf = (char *)XML_GetBuffer(parser, g_read_size_bytes);
|
char *buf = (char *)XML_GetBuffer(parser, g_read_size_bytes);
|
||||||
if (! buf) {
|
if (! buf) {
|
||||||
if (filename != NULL)
|
if (filename != NULL)
|
||||||
|
@ -201,14 +208,14 @@ processStream(const XML_Char *filename, XML_Parser parser) {
|
||||||
filename != NULL ? filename : T("xmlwf"));
|
filename != NULL ? filename : T("xmlwf"));
|
||||||
return 0;
|
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) {
|
if (nread < 0) {
|
||||||
tperror(filename != NULL ? filename : T("STDIN"));
|
tperror(filename != NULL ? filename : T("STDIN"));
|
||||||
if (filename != NULL)
|
if (filename != NULL)
|
||||||
close(fd);
|
close(fd);
|
||||||
return 0;
|
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"));
|
reportError(parser, filename != NULL ? filename : T("STDIN"));
|
||||||
if (filename != NULL)
|
if (filename != NULL)
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
|
@ -305,7 +305,7 @@ static XML_Char *
|
||||||
xcsdup(const XML_Char *s) {
|
xcsdup(const XML_Char *s) {
|
||||||
XML_Char *result;
|
XML_Char *result;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int numBytes;
|
size_t numBytes;
|
||||||
|
|
||||||
/* Get the length of the string, including terminator */
|
/* Get the length of the string, including terminator */
|
||||||
while (s[count++] != 0) {
|
while (s[count++] != 0) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue