intel / libvpl

Intel® Video Processing Library (Intel® VPL) API, dispatcher, and examples
https://intel.github.io/libvpl/
MIT License
262 stars 80 forks source link

replace PATH_MAX with realpath in dispatcher_util test #85

Closed zlice closed 1 year ago

zlice commented 1 year ago

Was not building for a CI musl build. Undefined PATH_MAX, defined in linux/limits.h.

StefanBruens commented 1 year ago

The correct fix is to remove the usage of PATH_MAX via realpath altogether. From the realpath man page:

BUGS The POSIX.1-2001 standard version of this function is broken by design, since it is impossible to determine a suitable size for the output buffer, resolved_path. According to POSIX.1-2001 a buffer of size PATH_MAX suffices, but PATH_MAX need not be a defined constant, and may have to be obtained using pathconf(3). And asking pathconf(3) does not really help, since, on the one hand POSIX warns that the result of pathconf(3) may be huge and unsuitable for mallocing memory, and on the other hand pathconf(3) may return -1 to signify that PATH_MAX is not bounded. The resolved_path == NULL feature, not standardized in POSIX.1-2001, but standardized in POSIX.1-2008, allows this design problem to be avoided.

jonrecker commented 1 year ago

Thank you @StefanBruens for the review and suggestion. According to the man page snippet, setting resolved_path to NULL and letting realpath() allocate the correct-sized buffer avoids the problem. The usage here would look something like

// convert to canonical, absolute path
char *fullPath = realpath(workDirPath.c_str(), NULL);
if (!fullPath)
    return -1;
workDirPath = fullPath; // copy to std::string
free(fullPath);

@zlice would you like to try this change with your build, and if it works update your PR?

zlice commented 1 year ago

LGTM - thanks stefan

jonrecker commented 1 year ago

Thank you for the PR. Your commit has been merged to a staging repo for validation and will be merged to the main branch in this repo in the next release (v2023.1.2). Your commit will retain the original author, message, etc. We did have to shorten the title slightly to pass lint checking (max 50 chars - unfortunately this is not automated, but may be run locally with 'script/lint') It will appear as 'Replace PATH_MAX with realpath in dispatcher_util'

mav-intel commented 1 year ago

Merged in 37e96308345a08217b9737a98f27454ad42eb908