toml11/toml
Moritz Klammler cf8a977be2 Don't deliberately dereference the null pointer
This patch addresses a static analysis issue reported by Cppcheck 2.9
where several member functions of the toml::discard_comment class
defined in the toml/comments.hpp header were implemented to deliberately
dereference the null pointer returned unconditionally by the
always-empty container's data() member function.  This behavior wasn't
technically wrong because those functions all have as precondition that
the container is non-empty so they must never be called on an instance
of toml::discard_comment but we can still be more helpful without
adversely affecting code generation.  Instead of dereferencing the null
pointer, this patch has these functions call an inline private helper
function which is defined to invoke __builtin_unreachable() if available
"and then" throw an exception with a helpful error message.  Even at the
-O1 level, GCC will optimize the code under the assumption that the
function will never be called (i.e. no assembly is emitted), making
failure to ensure this undefined behavior exactly as if the null pointer
had been dereferenced.  However, static analysis will now understand the
programmer's intent and remain silent.  Furthermore, when using the -O0
or -Og levels, GCC won't optimize under this assumption so the exception
will be thrown and might be helpful for debugging.  Compilers that don't
have __builtin_unreachable() won't get any help in determining that the
function must not be called and will have to figure this out by
analyzing the calling code -- which really shouldn't exist in the first
place anyway as the whole point is that these functions must not be
called.
2022-09-29 17:59:28 +02:00
..
color.hpp refactor: style update 2022-05-29 00:37:39 +09:00
combinator.hpp fix a compile warning C26478 2021-10-09 11:12:58 +09:00
comments.hpp Don't deliberately dereference the null pointer 2022-09-29 17:59:28 +02:00
datetime.hpp Initialize data members for defaulted c'tors 2022-09-29 17:59:27 +02:00
exception.hpp fix: add missing include file and specifiers 2022-09-29 20:14:58 +09:00
from.hpp fix: remove needless include file 2021-05-25 21:40:41 +09:00
get.hpp fix #177: check specific conversion function 2021-12-25 14:08:55 +09:00
into.hpp fix: remove needless include file 2021-05-25 21:40:41 +09:00
lexer.hpp Merge pull request #193 from lukash/replace-fstream 2022-09-24 00:17:52 +09:00
literal.hpp fix: disallow null char at the end of input 2021-12-14 22:33:58 +09:00
macros.hpp
parser.hpp fix: use fs::path, not fs::path::string() result 2022-09-29 21:28:35 +09:00
region.hpp Don't compare iterators from potentially different containers 2022-09-29 17:59:28 +02:00
result.hpp
serializer.hpp fix: serializer has wrong constructor params order when format root object 2021-09-22 11:38:42 +08:00
source_location.hpp Support changing color mode at runtime 2022-05-27 00:01:28 +09:00
storage.hpp
string.hpp feat: workaround __cplusplus problem on MSVC 2021-12-17 22:29:57 +09:00
traits.hpp feat: workaround __cplusplus problem on MSVC 2021-12-17 22:29:57 +09:00
types.hpp Spelling fixes 2021-08-27 19:52:45 -04:00
utility.hpp feat: workaround __cplusplus problem on MSVC 2021-12-17 22:29:57 +09:00
value.hpp fix: #192 quick fix by checking address 2022-07-01 01:09:22 +09:00
version.hpp fix: Allow MSVC to have old version 2021-12-18 00:36:20 +09:00