Skip to content

Commit f7c3a4b

Browse files
committed
Fix JBMC crash on windows in NondetEnumOpaqueReturn test
String literals with multibyte utf-8 characters in java cause `ch` to be negative. Passing a negative value into `std::isalnum` results in undefined behaviour. On windows the observed behaviour is a popup error message about a failed assertion in the run time library. This stalls the CI process as none of the buttons on the popup message ever get pressed. Escaping these characters is sufficient to fix the stalling test.
1 parent d70285a commit f7c3a4b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/util/string_utils.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Author: Daniel Poetzl
99
#include "string_utils.h"
1010
#include "exception_utils.h"
1111
#include "invariant.h"
12+
#include "narrow.h"
1213

1314
#include <algorithm>
1415
#include <cassert>
@@ -156,9 +157,10 @@ std::string escape_non_alnum(const std::string &to_escape)
156157
std::ostringstream escaped;
157158
for(auto &ch : to_escape)
158159
{
160+
const auto uch = narrow<int>(narrow_cast<unsigned char>(ch));
159161
if(ch == '_')
160162
escaped << "__";
161-
else if(isalnum(ch))
163+
else if(isalnum(uch))
162164
escaped << ch;
163165
else
164166
escaped << '_' << std::hex << std::setfill('0') << std::setw(2)

0 commit comments

Comments
 (0)