From 62760d707d66f75601f78afba0f67872b8d59155 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 30 Jul 2026 00:57:30 +0200 Subject: [PATCH] libxml: Fix an ISO C undefined behaviour. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. --- gnulib-local/lib/libxml/parser.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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 */ } } -- 2.47.3