Merge pull request #36 from bdrewery/fix-crash-without-pathseps

Fix crash when specified filename has no path separators
pull/37/head
Baptiste Daroussin 2012-08-25 15:15:08 -07:00
commit 5bd921b312
1 changed files with 6 additions and 4 deletions

10
pkg.c
View File

@ -131,8 +131,8 @@ pkg_get_parent_dir(pkg_t *pkg)
char *pathbuf;
strlcpy(buf, pkg->filename, sizeof buf);
pathbuf = strrchr(buf, PKG_DIR_SEP_S);
pathbuf[0] = '\0';
if ((pathbuf = strrchr(buf, PKG_DIR_SEP_S)) != NULL)
pathbuf[0] = '\0';
return buf;
}
@ -154,8 +154,10 @@ pkg_new_from_file(const char *filename, FILE *f)
pkg->vars = pkg_tuple_add(pkg->vars, "pcfiledir", pkg_get_parent_dir(pkg));
/* make module id */
idptr = strrchr(pkg->filename, PKG_DIR_SEP_S);
idptr++;
if ((idptr = strrchr(pkg->filename, PKG_DIR_SEP_S)) != NULL)
idptr++;
else
idptr = pkg->filename;
pkg->id = strdup(idptr);
idptr = strrchr(pkg->id, '.');