Avoid undefined behaviour const_casting std::string c_str()

Use non-const data() instead

See: #224
This commit is contained in:
Jonathan G Rennison
2021-03-11 01:08:33 +00:00
parent 63d1fe4419
commit 4361a6dbf4
10 changed files with 18 additions and 17 deletions

View File

@@ -946,7 +946,7 @@ void NetworkGameLoop()
cp->text.resize(MAX_CMD_TEXT_LENGTH);
static_assert(MAX_CMD_TEXT_LENGTH > 8192);
int ret = sscanf(p, "date{%x; %x; %x}; company: %x; tile: %x (%*u x %*u); p1: %x; p2: %x; p3: " OTTD_PRINTFHEX64 "; cmd: %x; \"%8192[^\"]\"",
&next_date, &next_date_fract, &next_tick_skip_counter, &company, &cp->tile, &cp->p1, &cp->p2, &cp->p3, &cp->cmd, const_cast<char *>(cp->text.c_str()));
&next_date, &next_date_fract, &next_tick_skip_counter, &company, &cp->tile, &cp->p1, &cp->p2, &cp->p3, &cp->cmd, cp->text.data());
/* There are 10 pieces of data to read, however the last is a
* string that might or might not exist. Ignore it if that
* string misses because in 99% of the time it's not used. */