mirror of
https://github.com/libexpat/libexpat.git
synced 2025-04-04 21:04:57 +00:00
fuzz: Address clang-tidy bugprone-narrowing-conversions
The symptom was: > [..]/expat/fuzz/xml_parse_fuzzer.c:68:40: error: narrowing conversion from 'size_t' (aka 'unsigned long') to signed type 'int' is implementation-defined [bugprone-narrowing-conversions,-warnings-as-errors] > 68 | XML_Parse(p, (const XML_Char *)data, size, 0); > | ^ > [..]/expat/fuzz/xml_parse_fuzzer.c:69:44: error: narrowing conversion from 'size_t' (aka 'unsigned long') to signed type 'int' is implementation-defined [bugprone-narrowing-conversions,-warnings-as-errors] > 69 | if (XML_Parse(p, (const XML_Char *)data, size, 1) == XML_STATUS_ERROR) { > | ^ > [..]/expat/fuzz/xml_parsebuffer_fuzzer.c:69:32: error: narrowing conversion from 'size_t' (aka 'unsigned long') to signed type 'int' is implementation-defined [bugprone-narrowing-conversions,-warnings-as-errors] > 69 | void *buf = XML_GetBuffer(p, size); > | ^ > [..]/expat/fuzz/xml_parsebuffer_fuzzer.c:72:22: error: narrowing conversion from 'size_t' (aka 'unsigned long') to signed type 'int' is implementation-defined [bugprone-narrowing-conversions,-warnings-as-errors] > 72 | XML_ParseBuffer(p, size, 0); > | ^ > [..]/expat/fuzz/xml_parsebuffer_fuzzer.c:73:26: error: narrowing conversion from 'size_t' (aka 'unsigned long') to signed type 'int' is implementation-defined [bugprone-narrowing-conversions,-warnings-as-errors] > 73 | buf = XML_GetBuffer(p, size); > | ^ > [..]/expat/fuzz/xml_parsebuffer_fuzzer.c:78:26: error: narrowing conversion from 'size_t' (aka 'unsigned long') to signed type 'int' is implementation-defined [bugprone-narrowing-conversions,-warnings-as-errors] > 78 | if (XML_ParseBuffer(p, size, 1) == XML_STATUS_ERROR) { > | ^
This commit is contained in:
parent
94cceb228c
commit
57a7643252
2 changed files with 10 additions and 6 deletions
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h> // for INT_MAX
|
||||
#include <stdint.h>
|
||||
|
||||
#include "expat.h"
|
||||
|
@ -65,8 +66,9 @@ ParseOneInput(XML_Parser p, const uint8_t *data, size_t size) {
|
|||
XML_SetUserData(p, p);
|
||||
XML_SetElementHandler(p, start, end);
|
||||
XML_SetCharacterDataHandler(p, may_stop_character_handler);
|
||||
XML_Parse(p, (const XML_Char *)data, size, 0);
|
||||
if (XML_Parse(p, (const XML_Char *)data, size, 1) == XML_STATUS_ERROR) {
|
||||
assert(size <= INT_MAX);
|
||||
XML_Parse(p, (const XML_Char *)data, (int)size, 0);
|
||||
if (XML_Parse(p, (const XML_Char *)data, (int)size, 1) == XML_STATUS_ERROR) {
|
||||
XML_ErrorString(XML_GetErrorCode(p));
|
||||
}
|
||||
XML_GetCurrentLineNumber(p);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h> // for INT_MAX
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@ -66,16 +67,17 @@ ParseOneInput(XML_Parser p, const uint8_t *data, size_t size) {
|
|||
XML_SetUserData(p, p);
|
||||
XML_SetElementHandler(p, start, end);
|
||||
XML_SetCharacterDataHandler(p, may_stop_character_handler);
|
||||
void *buf = XML_GetBuffer(p, size);
|
||||
assert(size <= INT_MAX);
|
||||
void *buf = XML_GetBuffer(p, (int)size);
|
||||
assert(buf);
|
||||
memcpy(buf, data, size);
|
||||
XML_ParseBuffer(p, size, 0);
|
||||
buf = XML_GetBuffer(p, size);
|
||||
XML_ParseBuffer(p, (int)size, 0);
|
||||
buf = XML_GetBuffer(p, (int)size);
|
||||
if (buf == NULL) {
|
||||
return;
|
||||
}
|
||||
memcpy(buf, data, size);
|
||||
if (XML_ParseBuffer(p, size, 1) == XML_STATUS_ERROR) {
|
||||
if (XML_ParseBuffer(p, (int)size, 1) == XML_STATUS_ERROR) {
|
||||
XML_ErrorString(XML_GetErrorCode(p));
|
||||
}
|
||||
XML_GetCurrentLineNumber(p);
|
||||
|
|
Loading…
Add table
Reference in a new issue