libretro-common: vfs_hybrid: replace strdup with C89-clean copy

strdup is POSIX, not C89: under a strict-C89 toolchain string.h hides
the prototype, the call becomes an implicit declaration returning int,
and on LP64 the pointer is truncated.  It compiled quietly so far only
because every current consumer builds with gnu language modes.  Caught
by the gcc -std=c89 -pedantic gate while wiring vfs_hybrid.c into the
frontend build.

Copy manually with malloc+memcpy from the headers already included.
NULL-on-OOM semantics for f->path are unchanged from strdup.

Mirrors the identical fix submitted to upstream libretro-common.

Verification: gcc -std=c89 -pedantic -Wall -Wextra compile, zero
warnings.  ASan+UBSan+LSan and TSan harness (hybrid install via fake
frontend VFS, 1000x open/read/close cycles through the front door
exercising the path copy alloc/free, plus the no-frontend init path):
clean.  TSan run is single-threaded; no concurrency is touched by this
diff.
This commit is contained in:
LibretroAdmin authored and libretroadmin committed 2026-08-10 20:10:28 +02:00
1 parent aa125ed759
commit c46b14a79b
1 file changed
+10 -1
+10 -1
View File
@@ -123,7 +123,16 @@ static struct retro_vfs_file_handle *hyb_open( const char *path, unsigned mode,
}
f->be = be;
f->h = h;
f->path = strdup( path );
/* strdup is POSIX, not C89: under a strict-C89 toolchain the
prototype is hidden and the implicit int return truncates the
pointer on LP64. Copy manually with the headers we already
include. */
{
size_t path_len = strlen( path ) + 1;
f->path = (char *)malloc( path_len );
if ( f->path )
memcpy( f->path, path, path_len );
}
return (struct retro_vfs_file_handle *)f;
}