Skip to content

Commit 8f31ec8

Browse files
committed
fixed #187
also: - fixed #188 - fixed #189 - updated conformance tests - version bump
1 parent d00464a commit 8f31ec8

12 files changed

+7551
-4035
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@ template:
2121
2222
-->
2323

24-
## Unreleased
24+
## v3.3.0
25+
26+
[Released](https://github.com/marzer/tomlplusplus/releases/tag/v3.3.0) 2023-01-29
2527

2628
#### Fixes:
2729

2830
- fixed null pointer dereference in parser when exceptions are disabled (#169) (@ncaklovic)
2931
- fixed spurious warnings in MSVC 19.34
3032
- fixed `toml::parse_file()` on windows for non-ASCII paths
33+
- fixed a spurious table redefinition error (#187) (@jorisvr)
34+
- fixed UB edge-case in integer parsing (#188) (@jorisvr)
35+
- fixed some build issues with Apple-flavoured Clang (#189) (@eddelbuettel)
3136

3237
#### Additions:
3338

include/toml++/impl/parser.inl

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,14 +2262,21 @@ TOML_IMPL_NAMESPACE_START
22622262
}
22632263

22642264
// range check
2265-
if TOML_UNLIKELY(result > static_cast<uint64_t>((std::numeric_limits<int64_t>::max)()) + (sign < 0 ? 1ull : 0ull))
2265+
static constexpr auto i64_max = static_cast<uint64_t>((std::numeric_limits<int64_t>::max)());
2266+
if TOML_UNLIKELY(result > i64_max + (sign < 0 ? 1u : 0u))
22662267
set_error_and_return_default("'"sv,
22672268
traits::full_prefix,
22682269
std::string_view{ digits, length },
22692270
"' is not representable in 64 bits"sv);
22702271

22712272
if constexpr (traits::is_signed)
2273+
{
2274+
// avoid signed multiply UB when parsing INT64_MIN
2275+
if TOML_UNLIKELY(sign < 0 && result == i64_max + 1u)
2276+
return (std::numeric_limits<int64_t>::min)();
2277+
22722278
return static_cast<int64_t>(result) * sign;
2279+
}
22732280
else
22742281
return static_cast<int64_t>(result);
22752282
}
@@ -3252,13 +3259,28 @@ TOML_IMPL_NAMESPACE_START
32523259

32533260
else if (auto tbl = matching_node.as_table(); !is_arr && tbl && !implicit_tables.empty())
32543261
{
3255-
if (auto found = impl::find(implicit_tables.begin(), implicit_tables.end(), tbl);
3256-
found && (tbl->empty() || tbl->is_homogeneous<table>()))
3262+
if (auto found = impl::find(implicit_tables.begin(), implicit_tables.end(), tbl); found)
32573263
{
3258-
implicit_tables.erase(implicit_tables.cbegin() + (found - implicit_tables.data()));
3259-
tbl->source_.begin = header_begin_pos;
3260-
tbl->source_.end = header_end_pos;
3261-
return tbl;
3264+
bool ok = true;
3265+
if (!tbl->empty())
3266+
{
3267+
for (auto& [_, child] : *tbl)
3268+
{
3269+
if (!child.is_table() && !child.is_array_of_tables())
3270+
{
3271+
ok = false;
3272+
break;
3273+
}
3274+
}
3275+
}
3276+
3277+
if (ok)
3278+
{
3279+
implicit_tables.erase(implicit_tables.cbegin() + (found - implicit_tables.data()));
3280+
tbl->source_.begin = header_begin_pos;
3281+
tbl->source_.end = header_end_pos;
3282+
return tbl;
3283+
}
32623284
}
32633285
}
32643286

include/toml++/impl/preprocessor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@
515515
__pragma(warning(push)) \
516516
static_assert(true)
517517

518-
#if TOML_HAS_INCLUDE(<CodeAnalysis / Warnings.h>)
518+
#if TOML_HAS_INCLUDE(<CodeAnalysis/Warnings.h>)
519519
#pragma warning(push, 0)
520520
#include <CodeAnalysis/Warnings.h>
521521
#pragma warning(pop)

include/toml++/impl/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#pragma once
66

77
#define TOML_LIB_MAJOR 3
8-
#define TOML_LIB_MINOR 2
8+
#define TOML_LIB_MINOR 3
99
#define TOML_LIB_PATCH 0
1010

1111
#define TOML_LANG_MAJOR 1

include/toml++/toml.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
#define INCLUDE_TOMLPLUSPLUS_H // old guard name used pre-v3
99

10-
//# Note: these would be included transitively as with any normal C++ project but
11-
//# they're listed explicitly here because this file is used as the source for generate_single_header.py.
12-
1310
#include "impl/preprocessor.h"
1411

1512
TOML_PUSH_WARNINGS;
@@ -24,12 +21,12 @@ TOML_DISABLE_SUGGEST_ATTR_WARNINGS;
2421
#pragma warning(disable : 4251) // dll exports for std lib types
2522
#endif
2623
#elif TOML_CLANG
27-
#pragma clang diagnostic ignored "-Wheader-hygiene"
24+
TOML_PRAGMA_CLANG(diagnostic ignored "-Wheader-hygiene")
2825
#if TOML_CLANG >= 12
29-
#pragma clang diagnostic ignored "-Wc++20-extensions"
26+
TOML_PRAGMA_CLANG(diagnostic ignored "-Wc++20-extensions")
3027
#endif
31-
#if TOML_CLANG == 13 && !defined(__APPLE__)
32-
#pragma clang diagnostic ignored "-Wreserved-identifier"
28+
#if TOML_CLANG == 13
29+
TOML_PRAGMA_CLANG(diagnostic ignored "-Wreserved-identifier")
3330
#endif
3431
#endif
3532

0 commit comments

Comments
 (0)