Skip to content

Commit

Permalink
libponyc/program: simplify use_path
Browse files Browse the repository at this point in the history
Now, this is relying on path_cat to do copying (including length checks).

Signed-off-by: Stephan Renatus <srenatus@chef.io>
  • Loading branch information
srenatus committed Jan 14, 2019
1 parent 1972e80 commit 628772b
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/libponyc/pkg/program.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,14 @@ bool use_path(ast_t* use, const char* locator, ast_t* name,
{
(void)name;
char absolute[FILENAME_MAX];
const char* prefix = NULL;

ast_t* pkg_ast = ast_nearest(use, TK_PACKAGE);
const char* pkg_path = package_path(pkg_ast);

if(is_path_absolute(locator)) {
if(strlen(locator) > FILENAME_MAX)
return false;

strcpy(absolute, locator);
} else {
// resolve path relative to pkg path
if(strlen(pkg_path) + strlen(locator) >= FILENAME_MAX)
return false;

path_cat(pkg_path, locator, absolute);
if(!is_path_absolute(locator)) {
ast_t* pkg_ast = ast_nearest(use, TK_PACKAGE);
prefix = package_path(pkg_ast);
}

path_cat(prefix, locator, absolute);
const char* libpath = quoted_locator(options, use, absolute);

if(libpath == NULL)
Expand Down

0 comments on commit 628772b

Please sign in to comment.