Skip to content

Commit

Permalink
Fix crash when argc is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
parasti committed Sep 8, 2019
1 parent 50520e8 commit 09a2a62
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ball/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ int main(int argc, char *argv[])
{
int t1, t0;

if (!fs_init(argv[0]))
if (!fs_init(argc > 0 ? argv[0] : NULL))
{
fprintf(stderr, "Failure to initialize virtual file system (%s)\n",
fs_error());
Expand Down
2 changes: 1 addition & 1 deletion putt/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ int main(int argc, char *argv[])
{
int camera = 0;

if (!fs_init(argv[0]))
if (!fs_init(argc > 0 ? argv[0] : NULL))
{
fprintf(stderr, "Failure to initialize virtual file system (%s)\n",
fs_error());
Expand Down
21 changes: 12 additions & 9 deletions share/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,20 +299,23 @@ const char *base_name(const char *name)

const char *dir_name(const char *name)
{
static char buff[MAXSTR];
if (name && *name)
{
static char buff[MAXSTR];

char *sep;
char *sep;

SAFECPY(buff, name);
SAFECPY(buff, name);

if ((sep = (char *) path_last_sep(buff)))
{
if (sep == buff)
return "/";
if ((sep = (char *) path_last_sep(buff)))
{
if (sep == buff)
return "/";

*sep = '\0';
*sep = '\0';

return buff;
return buff;
}
}

return ".";
Expand Down
2 changes: 1 addition & 1 deletion share/fs_stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static List fs_path;

int fs_init(const char *argv0)
{
fs_dir_base = strdup(dir_name(argv0));
fs_dir_base = strdup(argv0 && *argv0 ? dir_name(argv0) : ".");
fs_dir_write = NULL;
fs_path = NULL;

Expand Down
2 changes: 1 addition & 1 deletion share/mapc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2811,7 +2811,7 @@ int main(int argc, char *argv[])
struct timeval time0;
struct timeval time1;

if (!fs_init(argv[0]))
if (!fs_init(argc > 0 ? argv[0] : NULL))
{
fprintf(stderr, "Failure to initialize virtual file system: %s\n",
fs_error());
Expand Down

0 comments on commit 09a2a62

Please sign in to comment.