[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master b3e933e2: Trap ludicrous values
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master b3e933e2: Trap ludicrous values |
Date: |
Wed, 29 Jun 2022 17:17:36 -0400 (EDT) |
branch: master
commit b3e933e24484a77b81fd1f51b44ed6e99539c5d5
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Trap ludicrous values
This improves commit 3a5c416d4e; see:
https://lists.nongnu.org/archive/html/lmi/2022-06/msg00081.html
---
rate_table.cpp | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/rate_table.cpp b/rate_table.cpp
index 99cfdda0..24ccfba9 100644
--- a/rate_table.cpp
+++ b/rate_table.cpp
@@ -36,6 +36,7 @@
# include <bit> // endian
#endif // 202002 <= __cplusplus
#include <climits> // ULLONG_MAX
+#include <cstdint> // intmax_t
#include <cstdlib> // strtoull()
#include <cstring> // memcpy(), strncmp()
#include <iomanip>
@@ -338,14 +339,23 @@ char const* table_type_as_string(table_type tt)
// Represents location in the input, possibly invalid if it's not available.
struct location_info
{
- explicit location_info(int line_num = 0, long long int position = 0)
+ explicit location_info(int line_num = 0, int position = 0)
:line_num_ {line_num}
,position_ {position}
{
}
- int const line_num_ = 0;
- long long int const position_ = 0;
+ // Some invocations pass a 'position' of a wide type. Ideally
+ // each would be rewritten; this overload is an expedient stopgap
+ // to trap any ludicrous value.
+ explicit location_info(int line_num, std::intmax_t position)
+ :line_num_ {line_num}
+ ,position_ {bourn_cast<int>(position)}
+ {
+ }
+
+ int const line_num_ = 0;
+ int const position_ = 0;
};
inline
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [lmi] master b3e933e2: Trap ludicrous values,
Greg Chicares <=