Skip to content

Commit a33729f

Browse files
committed
win32.c: don't call wcscpy() with in == out
Since both the input and output parameters are restrict qualified, this would be invalid, and it is possibe for PerlDir_mapW() to return its parameter. This warned on gcc: win32.c: In function 'win32_link': win32.c:3712:40: warning: passing argument 1 to 'restrict'-qualified parameter aliases with argument 2 [-Wrestrict] 3712 | ((aTHXa(PERL_GET_THX)), wcscpy(wOldName, PerlDir_mapW(wOldName)), | ^~~~~~~~
1 parent 224c53d commit a33729f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

win32/win32.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3700,6 +3700,17 @@ win32_pclose(PerlIO *pf)
37003700
#endif /* USE_RTL_POPEN */
37013701
}
37023702

3703+
/* wcscpy() arguments are restrict qualified, but if they're equal
3704+
we don't need to do the copy
3705+
*/
3706+
static inline WCHAR *
3707+
cond_wcsncpy(WCHAR *out, const WCHAR *in, size_t n) {
3708+
assert(wcslen(in) < n);
3709+
if (out != in)
3710+
wcsncpy(out, in, n);
3711+
return out;
3712+
}
3713+
37033714
DllExport int
37043715
win32_link(const char *oldname, const char *newname)
37053716
{
@@ -3709,7 +3720,8 @@ win32_link(const char *oldname, const char *newname)
37093720

37103721
if (MultiByteToWideChar(CP_ACP, 0, oldname, -1, wOldName, MAX_PATH+1) &&
37113722
MultiByteToWideChar(CP_ACP, 0, newname, -1, wNewName, MAX_PATH+1) &&
3712-
((aTHXa(PERL_GET_THX)), wcscpy(wOldName, PerlDir_mapW(wOldName)),
3723+
((aTHXa(PERL_GET_THX)),
3724+
cond_wcsncpy(wOldName, PerlDir_mapW(wOldName), C_ARRAY_LENGTH(wOldName)),
37133725
CreateHardLinkW(PerlDir_mapW(wNewName), wOldName, NULL)))
37143726
{
37153727
return 0;

0 commit comments

Comments
 (0)