Fix the argv[0] == NULL bug
Signed-off-by: Gavin Howard <[email protected]>
This commit is contained in:
parent
52f7667c88
commit
81905ee8e2
24
src/main.c
24
src/main.c
|
@ -66,10 +66,26 @@ int main(int argc, char *argv[]) {
|
|||
// Set the start pledge().
|
||||
bc_pledge(bc_pledge_start, NULL);
|
||||
|
||||
// Figure out the name of the calculator we are using. We can't use basename
|
||||
// because it's not portable, but yes, this is stripping off the directory.
|
||||
name = strrchr(argv[0], BC_FILE_SEP);
|
||||
vm.name = (name == NULL) ? argv[0] : name + 1;
|
||||
// Sometimes, argv[0] can be NULL. Better make sure to be robust against it.
|
||||
if (argv[0] != NULL) {
|
||||
|
||||
// Figure out the name of the calculator we are using. We can't use
|
||||
// basename because it's not portable, but yes, this is stripping off
|
||||
// the directory.
|
||||
name = strrchr(argv[0], BC_FILE_SEP);
|
||||
vm.name = (name == NULL) ? argv[0] : name + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if !DC_ENABLED
|
||||
vm.name = "bc";
|
||||
#elif !BC_ENABLED
|
||||
vm.name = "dc";
|
||||
#else
|
||||
// Just default to bc in that case.
|
||||
vm.name = "bc";
|
||||
#endif
|
||||
}
|
||||
|
||||
// If the name is longer than the length of the prefix, skip the prefix.
|
||||
if (strlen(vm.name) > len) vm.name += len;
|
||||
|
|
Loadingâ¦
Reference in New Issue