1
mirror of https://github.com/flipperdevices/flipperzero-firmware.git synced 2025-12-12 04:41:26 +04:00

[FL-3884] Proper integer parsing (#3839)

* feat: strint_to_uint32 and tests
* fix: permit explicit bases and prefixes
* feat: strint_to_{int32,uint16,int16}
* feat: strint_to_u?int64
* refactor: replace strtol, strtoul, sscanf with strint_to_*
* fix: api symbols
* docs: document parameter `end` of strint_to_uint_32
* style: apply changes requested by hedger
* refactor: fix pvs-studio diagnostic
* style: apply changes requested by CookiePLMonster
* fix: unused var
* fix: pointer type
* refactor: convert atoi to strint_to_*
* fix: strint_to_uint8 doesn't actually exist ._ .
* fix: memory leak
* style: address review comments
* Toolbox: couple small comments in the code and doxygen comment update. SubGhz, Loader: fix strint usage.
* Loader: fix incorrect cast

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
porta
2024-09-05 20:02:42 +03:00
committed by GitHub
parent 6a48dd28f5
commit c9791a280a
21 changed files with 479 additions and 90 deletions

View File

@@ -1,5 +1,6 @@
#include <inttypes.h>
#include <toolbox/hex.h>
#include <toolbox/strint.h>
#include <core/check.h>
#include "flipper_format_stream.h"
#include "flipper_format_stream_i.h"
@@ -396,14 +397,16 @@ bool flipper_format_stream_read_value_line(
#endif
case FlipperStreamValueInt32: {
int32_t* data = _data;
scan_values = sscanf(furi_string_get_cstr(value), "%" PRIi32, &data[i]);
if(strint_to_int32(furi_string_get_cstr(value), NULL, &data[i], 10) ==
StrintParseNoError) {
scan_values = 1;
}
}; break;
case FlipperStreamValueUint32: {
uint32_t* data = _data;
// Minus sign is allowed in scanf() for unsigned numbers, resulting in unintentionally huge values with no error reported
if(!furi_string_start_with(value, "-")) {
scan_values =
sscanf(furi_string_get_cstr(value), "%" PRIu32, &data[i]);
if(strint_to_uint32(furi_string_get_cstr(value), NULL, &data[i], 10) ==
StrintParseNoError) {
scan_values = 1;
}
}; break;
case FlipperStreamValueHexUint64: {