From: Jesse Taube Date: Sat, 22 Jan 2022 00:44:36 +0000 (-0500) Subject: error checking X-Git-Url: https://repo.jachan.dev/imx_flashconf.git/commitdiff_plain/HEAD error checking --- diff --git a/imx-flashconf.c b/imx-flashconf.c index 5ff02da..1b2cd42 100644 --- a/imx-flashconf.c +++ b/imx-flashconf.c @@ -19,8 +19,8 @@ void prepend(FILE *, size_t); void list(const flash_configs *); int main(int argc, char *argv[]){ - char name[32]; - char fname[32]; + char name[32] = {}; + const char * fname; int opt; size_t index = 0; size_t padding = 0x1000; // default offset for nor @@ -44,7 +44,7 @@ int main(int argc, char *argv[]){ strncpy(name,optarg,32); break; case 'o': - strncpy(fname,optarg,32); + fname = optarg; break; case 'b': bin = strtol(optarg, NULL, 0); @@ -69,7 +69,9 @@ int main(int argc, char *argv[]){ puts("Need an output file name."); if(!strnlen(name,32)) puts("Need a flash config name."); - if(!strnlen(name,32) || !strnlen(fname,32)) + if(strnlen(name,32) == 32) + puts("Flash config name too long."); + if(!strnlen(name,32) || !strnlen(fname,32) || strnlen(name,32) == 32) help(-3); index = get_name_match(configs,name); diff --git a/mk.sh b/mk.sh index 64b7790..3a0d800 100755 --- a/mk.sh +++ b/mk.sh @@ -1,2 +1,2 @@ #!/usr/bin/bash -gcc -Wall imx-flashconf.c flash_confs.c -o imx-flashconf \ No newline at end of file +gcc -Wall imx-flashconf.c flash_confs.c -o imx-flashconf