Skip to content

Commit

Permalink
Fix for the initialisation of NaN and Inf crashing on RO 5.
Browse files Browse the repository at this point in the history
On RISC OS 5 (and 3.7) it appears that the initialisation of the
NaN and Inf variables was crashing. It's unclear why that is, but
to avoid the problem the variables are now initialised with their
constant values which should ensure that the tool starts, even
if the actual use of such values might be bad.

Version number incremented to 1.40.
  • Loading branch information
gerph committed Aug 17, 2021
1 parent 3966840 commit b190900
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
22 changes: 11 additions & 11 deletions RISCOS/VersionNum
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/* LibXML2 (1.39) 19:44:14 20/6/2021
/* LibXML2 (1.40) 21:25:28 17/8/2021
*
* This file is automatically maintained, do not edit manually.
*
*/
#define Module_MajorVersion_CMHG 1.39
#define Module_MajorVersion_CMHG 1.40
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 20 Jun 2021
#define Module_Date_CMHG 17 Aug 2021

#define Module_MajorVersion "1.39"
#define Module_Version 139
#define Module_MajorVersion "1.40"
#define Module_Version 140
#define Module_MinorVersion ""
#define Module_Date "20 Jun 2021"
#define Module_Date "17 Aug 2021"

#define Module_ApplicationDate2 "20-Jun-21"
#define Module_ApplicationDate4 "20-Jun-2021"
#define Module_ApplicationDate2 "17-Aug-21"
#define Module_ApplicationDate4 "17-Aug-2021"

#define Module_ComponentName "LibXML2"
#define Module_ComponentBranch ""
#define Module_ComponentPath ""

#define Module_FullVersion "1.39"
#define Module_FullVersionAndDate "1.39 (20 Jun 2021)"
#define Module_HelpVersion "1.39 (20 Jun 2021)"
#define Module_FullVersion "1.40"
#define Module_FullVersionAndDate "1.40 (17 Aug 2021)"
#define Module_HelpVersion "1.40 (17 Aug 2021)"
25 changes: 18 additions & 7 deletions upstream/xpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,19 +500,30 @@ double xmlXPathNINF;
ATTRIBUTE_NO_SANITIZE("float-divide-by-zero")
void
xmlXPathInit(void) {
#ifdef __riscos
/* On RISC OS 3.7 and earlier and RISC OS 5 and later, it appears that attempts to assign
* a NaN by using `xmlXPathNAN = 0.0 / zero` results in a crash.
* This does not happen on RISC OS 4.
*
* Consequently it is unsafe to use the assignment mechanism below to generate the values
* to assign from. Presumably it'll also be dangerous to calculate them elsewhere as well,
* but for the purposes of getting XPath to initialise, we'll merely assign these valid
* values.
*/
unsigned long nan_value[] = {0x7ff80000, 0xe0000000};
unsigned long inf_value[] = {0x7ff00000, 0x00000000};
unsigned long ninf_value[] = {0xfff00000, 0x00000000};

memcpy(&xmlXPathNAN, (unsigned long *)nan_value, sizeof(xmlXPathNAN));
memcpy(&xmlXPathPINF, (unsigned long *)inf_value, sizeof(xmlXPathPINF));
memcpy(&xmlXPathNINF, (unsigned long *)ninf_value, sizeof(xmlXPathNINF));
#else
/* MSVC doesn't allow division by zero in constant expressions. */
double zero = 0.0;

#ifdef __riscos
/* Disable the FP signals here so that we can assign NaN */
void (*signal_handler)(int) = signal(SIGFPE, SIG_IGN);
#endif

xmlXPathNAN = 0.0 / zero;
xmlXPathPINF = 1.0 / zero;
xmlXPathNINF = -xmlXPathPINF;
#ifdef __riscos
signal(SIGFPE, signal_handler);
#endif
}

Expand Down

0 comments on commit b190900

Please sign in to comment.