Skip to content

Commit 39a53c4

Browse files
authored
archive_dev: Ensure path separator for local path (#524)
Fixes issue where fopen("test.txt","r") opens 3dstest.txt instead of test.txt. Also correct misuse of strncat() as count applies to src not dest. See: devkitPro/3ds-hbmenu@8136d94 devkitPro/newlib@806a4d3
1 parent 8d90551 commit 39a53c4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

libctru/source/archive_dev.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,11 @@ archive_fixpath(struct _reent *r,
205205
strncpy(__ctru_dev_path_buf, path, PATH_MAX);
206206
else
207207
{
208+
size_t cwdlen = strlen(dev->cwd);
208209
strncpy(__ctru_dev_path_buf, dev->cwd, PATH_MAX);
209210
__ctru_dev_path_buf[PATH_MAX] = '\0';
210-
strncat(__ctru_dev_path_buf, path, PATH_MAX);
211+
strncat(__ctru_dev_path_buf, "/", PATH_MAX - cwdlen);
212+
strncat(__ctru_dev_path_buf, path, PATH_MAX - cwdlen - 1);
211213
}
212214

213215
if(__ctru_dev_path_buf[PATH_MAX] != 0)

0 commit comments

Comments
 (0)