Skip to content

Commit 829ab7f

Browse files
refactor: convert atoi to strint_to_*
1 parent 809eee9 commit 829ab7f

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

applications/main/infrared/infrared_cli.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,11 @@ static bool infrared_cli_parse_raw(const char* str, InfraredSignal* signal) {
178178
}
179179

180180
uint32_t* timings = malloc(sizeof(uint32_t) * MAX_TIMINGS_AMOUNT);
181-
uint32_t frequency = atoi(frequency_str);
182-
float duty_cycle = (float)atoi(duty_cycle_str) / 100;
181+
uint32_t frequency;
182+
uint8_t duty_cycle_u8;
183+
if(!strint_to_uint32(frequency_str, NULL, &frequency, 10)) return false;
184+
if(!strint_to_uint8(duty_cycle_str, NULL, &duty_cycle_u8, 10)) return false;
185+
float duty_cycle = duty_cycle_u8 / 100.0f;
183186

184187
str += strlen(frequency_str) + strlen(duty_cycle_str) + INFRARED_CLI_BUF_SIZE;
185188

lib/subghz/subghz_file_encoder_worker.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <flipper_format/flipper_format.h>
55
#include <flipper_format/flipper_format_i.h>
66
#include <lib/subghz/devices/devices.h>
7+
#include <lib/toolbox/strint.h>
78

89
#define TAG "SubGhzFileEncoderWorker"
910

@@ -45,27 +46,26 @@ void subghz_file_encoder_worker_add_level_duration(
4546
}
4647

4748
bool subghz_file_encoder_worker_data_parse(SubGhzFileEncoderWorker* instance, const char* strStart) {
48-
char* str1;
49-
bool res = false;
5049
// Line sample: "RAW_Data: -1, 2, -2..."
5150

52-
// Look for a key in the line
53-
str1 = strstr(strStart, "RAW_Data: ");
51+
// Look for the key in the line
52+
char* str = strstr(strStart, "RAW_Data: ");
53+
bool res = false;
5454

55-
if(str1 != NULL) {
55+
if(str) {
5656
// Skip key
57-
str1 = strchr(str1, ' ');
58-
59-
// Check that there is still an element in the line
60-
while(strchr(str1, ' ') != NULL) {
61-
str1 = strchr(str1, ' ');
57+
str = strchr(str, ' ');
6258

63-
// Skip space
64-
str1 += 1;
65-
subghz_file_encoder_worker_add_level_duration(instance, atoi(str1));
59+
// Parse next element
60+
int32_t duration;
61+
while(strint_to_int32(str, (char**)&str, &duration, 10) == StrintParseNoError) {
62+
subghz_file_encoder_worker_add_level_duration(instance, duration);
63+
if(*str == ',') str++; // could also be `\0`
6664
}
65+
6766
res = true;
6867
}
68+
6969
return res;
7070
}
7171

lib/update_util/resources/manifest.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "manifest.h"
22

33
#include <toolbox/stream/buffered_file_stream.h>
4+
#include <toolbox/strint.h>
45
#include <toolbox/hex.h>
56

67
struct ResourceManifestReader {
@@ -97,7 +98,12 @@ ResourceManifestEntry* resource_manifest_reader_next(ResourceManifestReader* res
9798
furi_string_right(
9899
resource_manifest->linebuf, sizeof(resource_manifest->entry.hash) * 2 + 1);
99100

100-
resource_manifest->entry.size = atoi(furi_string_get_cstr(resource_manifest->linebuf));
101+
if(strint_to_uint32(
102+
furi_string_get_cstr(resource_manifest->linebuf),
103+
NULL,
104+
&resource_manifest->entry.size,
105+
10) != StrintParseNoError)
106+
break;
101107

102108
/* Remove size */
103109
size_t offs = furi_string_search_char(resource_manifest->linebuf, ':');

0 commit comments

Comments
 (0)