From: Bruno Haible Date: Wed, 29 Jul 2026 22:57:30 +0000 (+0200) Subject: libxml: Fix an ISO C undefined behaviour. X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;p=thirdparty%2Fgettext.git libxml: Fix an ISO C undefined behaviour. ISO C 23 ยง 6.5.7.(10) has requirements for pointer subtraction. Found by use of Fil-C. * gnulib-local/lib/libxml/parser.c (xmlParseStartTag2): Avoid invalid pointer subtraction. --- diff --git a/gnulib-local/lib/libxml/parser.c b/gnulib-local/lib/libxml/parser.c index d485a58b8..721904274 100644 --- a/gnulib-local/lib/libxml/parser.c +++ b/gnulib-local/lib/libxml/parser.c @@ -1,5 +1,5 @@ /* libxml2 - Library for parsing XML documents - * Copyright (C) 2006-2019 Free Software Foundation, Inc. + * Copyright (C) 2006-2026 Free Software Foundation, Inc. * * This file is not part of the GNU gettext program, but is used with * GNU gettext. @@ -9460,12 +9460,11 @@ next_attr: if (atts[i+2] != NULL) { /* * Arithmetic on dangling pointers is technically undefined - * behavior, but well... + * behavior. Therefore: */ - ptrdiff_t offset = ctxt->input->base - atts[i+2]; + atts[i+3] = ctxt->input->base + (atts[i+3] - atts[i+2]); /* value */ + atts[i+4] = ctxt->input->base + (atts[i+4] - atts[i+2]); /* valuend */ atts[i+2] = NULL; /* Reset repurposed namespace URI */ - atts[i+3] += offset; /* value */ - atts[i+4] += offset; /* valuend */ } }