Skip to content

Commit

Permalink
[bugfix]: #1428
Browse files Browse the repository at this point in the history
    - Added '-V' and '-F' option to the getopt_long() optstring.
    - Marked -F/--freq option with required argument.
    - Added NULL pointer checks to helper function arg_parse_freq().
  • Loading branch information
Sten committed Sep 30, 2024
1 parent e493109 commit 4832a96
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/st-util/gdb-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ int32_t parse_options(int32_t argc, char** argv, st_state_t *st) {
{"no-reset", optional_argument, NULL, 'n'},
{"hot-plug", optional_argument, NULL, 'n'},
{"connect-under-reset", optional_argument, NULL, 'u'},
{"freq", optional_argument, NULL, 'F'},
{"freq", required_argument, NULL, 'F'},
{"version", no_argument, NULL, 'V'},
{"semihosting", no_argument, NULL, SEMIHOSTING_OPTION},
{"serial", required_argument, NULL, SERIAL_OPTION},
Expand Down Expand Up @@ -152,11 +152,11 @@ int32_t parse_options(int32_t argc, char** argv, st_state_t *st) {
;


int32_t option_index = 0;
int option_index = 0;
int32_t c;
int32_t q;

while ((c = getopt_long(argc, argv, "hv::p:mnu", long_options, &option_index)) != -1)
while ((c = getopt_long(argc, argv, "hv::p:mnuF:V", long_options, &option_index)) != -1)
switch (c) {
case 0:
break;
Expand Down
24 changes: 14 additions & 10 deletions src/stlink-lib/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ uint32_t time_ms() {
}

int32_t arg_parse_freq(const char *str) {
char *tail;
int32_t value = (int32_t) strtol(str, &tail, 10);

if (tail[0] == 'M' && tail[1] == '\0') {
value = value*1000;
} else if ((tail[0] != 'k' || tail[1] != '\0') && tail[0] != '\0') {
return -1;
}

return value;
int32_t value = -1;
if (str != NULL) {
char* tail = NULL;
value = strtol(str, &tail, 10);
if (tail != NULL) {
if (tail[0] == 'M' && tail[1] == '\0') {
value = value*1000;
}
else if (tail[0] != '\0' && !(tail[0] == 'k' && tail[1] == '\0')) {
value = -1; /* error */
}
}
}
return value; /* frequency in kHz */
}

0 comments on commit 4832a96

Please sign in to comment.