Commit 85f5be05 authored by Patrick Storz's avatar Patrick Storz 🦄

Preferences: Work around issue with parsing unsigned integers

As we handle unsigned integers the same way as signed integers,
large unsigned values (notably RGBA values) overflow the signed type.

The issue became apparent when we switched from atoi to strtol in

While the former has undefined behavior for out of range numbers
it luckily seemed to "just" overflow as expected on supported OSs.

The latter however returns LONG_MAX (which for a 32-bit value is
0x7fffffff and turned out to show turquoise in unexpected places,
e.g. the default path highlighting color in node tool).

Avoid this by catching the error and try to parse as unsigned type
in this case (which will still overflow, but seems to have worked
as expected so far).
parent 3ee89811
Pipeline #65327907 passed with stages
in 118 minutes and 41 seconds
......@@ -176,7 +176,7 @@ guint32 SPItem::highlight_color() const {
static Inkscape::Preferences *prefs = Inkscape::Preferences::get();
return prefs->getInt("/tools/nodes/highlight_color", 0xff0000ff) | 0x00000000;
return prefs->getInt("/tools/nodes/highlight_color", 0xff0000ff);
......@@ -133,7 +133,7 @@ R"=====(
show_sample_in_list="1" use_svg2="0"
style="fill:black;fill-opacity:1;stroke:none;font-family:sans-serif;font-style:normal;font-weight:normal;font-size:40px;" selcue="1"/>
<eventcontext id="nodes" selcue="1" gradientdrag="1" highlight_color="4278190335" pathflash_enabled="1" pathflash_unselected="0" pathflash_timeout="500" show_handles="1" show_outline="0"
<eventcontext id="nodes" selcue="1" gradientdrag="1" highlight_color="0xff0000ff" pathflash_enabled="1" pathflash_unselected="0" pathflash_timeout="500" show_handles="1" show_outline="0"
sculpting_profile="1" single_node_transform_handles="0" show_transform_handles="0" live_outline="1" live_objects="1" show_helperpath="0" x="0" y="0" edit_clipping_paths="0" edit_masks="0" />
<eventcontext id="tweak" selcue="0" gradientdrag="0" show_handles="0" width="0.2" force="0.2" fidelity="0.5" usepressure="1" style="fill:red;stroke:none;" usecurrent="0"/>
<eventcontext id="spray" selcue="1" gradientdrag="0" usepressure="1" width="15" population="70" mode="1" rotation_variation="0" scale_variation="0" standard_deviation="70" mean="0"/>
......@@ -783,7 +783,23 @@ int Preferences::_extractInt(Entry const &v)
v.value_int = 0;
return false;
} else {
v.value_int = (int)strtol(s, nullptr, 0);
int val = 0;
// TODO: We happily save unsigned integers (notably RGBA values) as signed integers and overflow as needed.
// We should consider adding an unsigned integer type to preferences or use HTML colors where appropriate
// (the latter would breaks backwards compatibility, though)
errno = 0;
val = (int)strtol(s, nullptr, 0);
if (errno == ERANGE) {
errno = 0;
val = (int)strtoul(s, nullptr, 0);
if (errno == ERANGE) {
g_warning("Integer preference out of range: '%s' (raw value: %s)", v._pref_path.c_str(), s);
val = 0;
v.value_int = val;
return v.value_int;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment