Skip to content

Commit 7f621c8

Browse files
authored
Merge pull request #2958 from chrisr-diffblue/cleanup-format_strings
Cleanup error handling in format_strings.cpp
2 parents a04da2e + fead175 commit 7f621c8

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/goto-programs/format_strings.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Author: CM Wintersteiger
1111

1212
#include "format_strings.h"
1313

14+
#include <util/exception_utils.h>
1415
#include <util/std_types.h>
1516
#include <util/std_expr.h>
1617

@@ -37,7 +38,9 @@ void parse_flags(
3738
curtok.flags.push_back(format_tokent::flag_typet::SIGNED_SPACE); break;
3839
case '+':
3940
curtok.flags.push_back(format_tokent::flag_typet::SIGN); break;
40-
default: throw 0;
41+
default:
42+
throw unsupported_operation_exceptiont(
43+
std::string("unsupported format specifier flag: `") + *it + "'");
4144
}
4245
it++;
4346
}
@@ -175,7 +178,8 @@ void parse_conversion_specifier(
175178
}
176179

177180
default:
178-
throw std::string("unsupported format conversion specifier: `")+*it+"'";
181+
throw unsupported_operation_exceptiont(
182+
std::string("unsupported format conversion specifier: `") + *it + "'");
179183
}
180184
it++;
181185
}
@@ -210,7 +214,11 @@ format_token_listt parse_format_string(const std::string &arg_string)
210214
for( ; it!=arg_string.end() && *it!='%'; it++)
211215
tmp+=*it;
212216

213-
assert(!token_list.empty());
217+
INVARIANT(
218+
!token_list.empty() &&
219+
token_list.back().type == format_tokent::token_typet::TEXT,
220+
"must already have a TEXT token at the back of the token list");
221+
214222
token_list.back().value=tmp;
215223
}
216224
}

0 commit comments

Comments
 (0)