Skip to content

Commit

Permalink
fixed os.dir_name and os.base_name overwrites on linux devices
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfriend99 committed Dec 27, 2022
1 parent 3f7b690 commit 33eec15
Showing 1 changed file with 0 additions and 8 deletions.
8 changes: 0 additions & 8 deletions src/standard/os.c
Expand Up @@ -429,14 +429,10 @@ DECLARE_MODULE_METHOD(os__exists) {
DECLARE_MODULE_METHOD(os__dirname) {
ENFORCE_ARG_COUNT(dirname, 1);
ENFORCE_ARG_TYPE(dirname, 0, IS_STRING);
#ifndef _WIN32
char *dir = dirname(AS_STRING(args[0])->chars);
#else // looking at Windows MingW64 dirname overwritten original string
char *str = strdup(AS_STRING(args[0])->chars);
char *dir = dirname(str);
// we are not freeing str because dirname will modify str.
// therefore, dir == str
#endif
if(!dir) {
RETURN_VALUE(args[0]);
}
Expand All @@ -446,14 +442,10 @@ DECLARE_MODULE_METHOD(os__dirname) {
DECLARE_MODULE_METHOD(os__basename) {
ENFORCE_ARG_COUNT(basename, 1);
ENFORCE_ARG_TYPE(basename, 0, IS_STRING);
#ifndef _WIN32
char *dir = basename(AS_STRING(args[0])->chars);
#else // looking at Windows MingW64 basename overwritten original string
char *str = strdup(AS_STRING(args[0])->chars);
char *dir = basename(str);
// we are not freeing str because basename will modify str.
// therefore, dir == str
#endif
if(!dir) {
RETURN_VALUE(args[0]);
}
Expand Down

0 comments on commit 33eec15

Please sign in to comment.