Blob Blame History Raw
From c4df90861879f45b281c2a8e55212b711cfdbfa0 Mon Sep 17 00:00:00 2001
From: Mattias Ellert <mattias.ellert@physics.uu.se>
Date: Tue, 29 Mar 2022 15:30:20 +0200
Subject: [PATCH] Avoid crashes due to static initialization order

Most commonly seen on ppc64le. Backtrace:

===========================================================
The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum https://root.cern/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
 #11 ROOT::Experimental::RColor::toHex[abi:cxx11](unsigned char) (v=<optimized out>) at /usr/include/c++/11/ext/new_allocator.h:82
 #12 0x00007fff90c220ec in ROOT::Experimental::RColor::SetRGB (this=0x7fffeadf5d10, r=<optimized out>, g=<optimized out>, b=<optimized out>) at /usr/include/c++/11/ext/new_allocator.h:89
---
 graf2d/gpadv7/src/RColor.cxx | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/graf2d/gpadv7/src/RColor.cxx b/graf2d/gpadv7/src/RColor.cxx
index de325f1ea3..6878360073 100644
--- a/graf2d/gpadv7/src/RColor.cxx
+++ b/graf2d/gpadv7/src/RColor.cxx
@@ -232,10 +232,10 @@ std::vector<uint8_t> RColor::AsRGBA() const
 
 std::string RColor::toHex(uint8_t v)
 {
-   static const char *digits = "0123456789ABCDEF";
+   auto digits = [](auto d) { return d < 10 ? '0' + d : 'A' - 10 + d; };
    std::string res(2,'0');
-   res[0] = digits[v >> 4];
-   res[1] = digits[v & 0xf];
+   res[0] = digits(v >> 4);
+   res[1] = digits(v & 0xf);
    return res;
 }
 
-- 
2.35.1