Skip to content

Commit

Permalink
Fix assert failure in math parser, as C functions can't handle code p…
Browse files Browse the repository at this point in the history
…oints >= 255
  • Loading branch information
TinoDidriksen committed Jun 27, 2024
1 parent 9eb7e54 commit 6eb3e40
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/MathParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,15 @@ inline void MathParser::get_token() {
token = exp_ptr.substr(0, 1);
exp_ptr.remove_prefix(1);
}
else if (isalpha(exp_ptr[0])) {
else if (ISALPHA_C(exp_ptr[0])) {
token = exp_ptr.substr(0, exp_ptr.find_first_of(u" +-/*%^=()"));
exp_ptr.remove_prefix(token.size());
while (ISSPACE(exp_ptr[0])) {
exp_ptr.remove_prefix(1);
}
tok_type = (exp_ptr[0] == '(') ? FUNCTION : VARIABLE;
}
else if (isdigit(exp_ptr[0]) || exp_ptr[0] == '.') {
else if (ISDIGIT_C(exp_ptr[0]) || exp_ptr[0] == '.') {
token = exp_ptr.substr(0, exp_ptr.find_first_of(u" +-/*%^=()"));
exp_ptr.remove_prefix(token.size());
tok_type = NUMBER;
Expand Down
10 changes: 10 additions & 0 deletions src/inlines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,16 @@ inline bool ISSPACE(const Char* p) {
return ISSPACE(*p) && !ISESC(p);
}

template<typename Char>
inline bool ISALPHA_C(Char p) {
return (p < 255) && isalpha(p);
}

template<typename Char>
inline bool ISDIGIT_C(Char p) {
return (p < 255) && isdigit(p);
}

template<typename Char, typename C, size_t N>
inline size_t IS_ICASE(const Char* p, const C (&uc)[N], const C (&lc)[N]) {
// N - 1 due to null terminator for string constants
Expand Down
2 changes: 1 addition & 1 deletion src/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ constexpr auto CG3_COPYRIGHT_STRING = "Copyright (C) 2007-2024 GrammarSoft ApS.

constexpr uint32_t CG3_VERSION_MAJOR = 1;
constexpr uint32_t CG3_VERSION_MINOR = 4;
constexpr uint32_t CG3_VERSION_PATCH = 12;
constexpr uint32_t CG3_VERSION_PATCH = 13;
constexpr uint32_t CG3_REVISION = 13898;
constexpr uint32_t CG3_FEATURE_REV = 13898;
constexpr uint32_t CG3_TOO_OLD = 10373;
Expand Down

0 comments on commit 6eb3e40

Please sign in to comment.