1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-01-19 10:03:34 +03:00

Fix casting of line numbers in SAX2.c

The line member is an unsigned short. Avoids integer conversion warnings
with UBSan.

Also use USHRT_MAX instead of hard-coded constant.
This commit is contained in:
Nick Wellnhofer 2022-01-25 02:59:40 +01:00
parent 67c2e78b81
commit a647e43025

30
SAX2.c
View File

@ -1623,10 +1623,10 @@ xmlSAX2StartElement(void *ctx, const xmlChar *fullname, const xmlChar **atts)
ctxt->nodemem = -1;
if (ctxt->linenumbers) {
if (ctxt->input != NULL) {
if (ctxt->input->line < 65535)
ret->line = (short) ctxt->input->line;
if (ctxt->input->line < USHRT_MAX)
ret->line = (unsigned short) ctxt->input->line;
else
ret->line = 65535;
ret->line = USHRT_MAX;
}
}
@ -1887,10 +1887,10 @@ skip:
if (ctxt->linenumbers) {
if (ctxt->input != NULL) {
if (ctxt->input->line < 65535)
ret->line = (short) ctxt->input->line;
if (ctxt->input->line < USHRT_MAX)
ret->line = (unsigned short) ctxt->input->line;
else {
ret->line = 65535;
ret->line = USHRT_MAX;
if (ctxt->options & XML_PARSE_BIG_LINES)
ret->psvi = (void *) (ptrdiff_t) ctxt->input->line;
}
@ -2267,10 +2267,10 @@ xmlSAX2StartElementNs(void *ctx,
}
if (ctxt->linenumbers) {
if (ctxt->input != NULL) {
if (ctxt->input->line < 65535)
ret->line = (short) ctxt->input->line;
if (ctxt->input->line < USHRT_MAX)
ret->line = (unsigned short) ctxt->input->line;
else
ret->line = 65535;
ret->line = USHRT_MAX;
}
}
@ -2689,10 +2689,10 @@ xmlSAX2ProcessingInstruction(void *ctx, const xmlChar *target,
if (ctxt->linenumbers) {
if (ctxt->input != NULL) {
if (ctxt->input->line < 65535)
ret->line = (short) ctxt->input->line;
if (ctxt->input->line < USHRT_MAX)
ret->line = (unsigned short) ctxt->input->line;
else
ret->line = 65535;
ret->line = USHRT_MAX;
}
}
if (ctxt->inSubset == 1) {
@ -2749,10 +2749,10 @@ xmlSAX2Comment(void *ctx, const xmlChar *value)
if (ret == NULL) return;
if (ctxt->linenumbers) {
if (ctxt->input != NULL) {
if (ctxt->input->line < 65535)
ret->line = (short) ctxt->input->line;
if (ctxt->input->line < USHRT_MAX)
ret->line = (unsigned short) ctxt->input->line;
else
ret->line = 65535;
ret->line = USHRT_MAX;
}
}