File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
features/cellular/framework/AT Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -722,7 +722,19 @@ int32_t ATHandler::read_int()
722
722
return -1 ;
723
723
}
724
724
725
- return std::strtol (buff, NULL , 10 );
725
+ errno = 0 ;
726
+ char *endptr;
727
+ long result = std::strtol (buff, &endptr, 10 );
728
+ if ((result == LONG_MIN || result == LONG_MAX) && errno == ERANGE) {
729
+ return -1 ; // overflow/underflow
730
+ }
731
+ if (result < 0 ) {
732
+ return -1 ; // negative values are unsupported
733
+ }
734
+ if (*buff == ' \0 ' ) {
735
+ return -1 ; // empty string
736
+ }
737
+ return (int32_t ) result;
726
738
}
727
739
728
740
void ATHandler::set_delimiter (char delimiter)
Original file line number Diff line number Diff line change @@ -416,9 +416,9 @@ class ATHandler {
416
416
*/
417
417
ssize_t read_hex_string (char *str, size_t size);
418
418
419
- /* * Reads as string and converts result to integer. Supports only positive integers.
419
+ /* * Reads as string and converts result to integer. Supports only non-negative integers.
420
420
*
421
- * @return the positive integer or -1 in case of error.
421
+ * @return the non-negative integer or -1 in case of error.
422
422
*/
423
423
int32_t read_int ();
424
424
You can’t perform that action at this time.
0 commit comments