musl - musl - an implementation of the standard library for Linux-based systems

index : musl
musl - an implementation of the standard library for Linux-based systems
summary refs log tree commit diff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2018年02月24日 16:45:33 -0500
committerRich Felker <dalias@aerifal.cx>2018年02月24日 16:45:33 -0500
commit2fae10f887b48b809bac56e4ff8a5c3fd4525de3 (patch)
treef9699222bbdd13e75f6b5ecda6d11cbc54a3d9d5
parent455bd824457b3e6cc3998817aac4e500b027cc50 (diff)
downloadmusl-2fae10f887b48b809bac56e4ff8a5c3fd4525de3.tar.gz
fix aliasing violations in fgetpos/fsetpos
add a member of appropriate type to the fpos_t union so that accesses are well-defined. use long long instead of off_t since off_t is not always exposed in stdio.h and there's no namespace-clean alias for it. access is still performed using pointer casts rather than by naming the union member as a matter of style; to the extent possible, the naming of fields in opaque types defined in the public headers is not treated as an API contract with the implementation. access via the pointer cast is valid as long as the union has a member of matching type.
Diffstat
-rw-r--r--include/stdio.h 1
-rw-r--r--src/stdio/fgetpos.c 2
-rw-r--r--src/stdio/fsetpos.c 2
3 files changed, 3 insertions, 2 deletions
diff --git a/include/stdio.h b/include/stdio.h
index 7c4f9ee4..afadd912 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -49,6 +49,7 @@ extern "C" {
typedef union _G_fpos64_t {
char __opaque[16];
+ long long __lldata;
double __align;
} fpos_t;
diff --git a/src/stdio/fgetpos.c b/src/stdio/fgetpos.c
index c3fa0eb0..6eb361e1 100644
--- a/src/stdio/fgetpos.c
+++ b/src/stdio/fgetpos.c
@@ -4,7 +4,7 @@ int fgetpos(FILE *restrict f, fpos_t *restrict pos)
{
off_t off = __ftello(f);
if (off < 0) return -1;
- *(off_t *)pos = off;
+ *(long long *)pos = off;
return 0;
}
diff --git a/src/stdio/fsetpos.c b/src/stdio/fsetpos.c
index 5d76c8cd..6310424e 100644
--- a/src/stdio/fsetpos.c
+++ b/src/stdio/fsetpos.c
@@ -2,7 +2,7 @@
int fsetpos(FILE *f, const fpos_t *pos)
{
- return __fseeko(f, *(const off_t *)pos, SEEK_SET);
+ return __fseeko(f, *(const long long *)pos, SEEK_SET);
}
LFS64(fsetpos);
generated by cgit v1.2.1 (git 2.18.0) at 2025年09月27日 03:20:28 +0000

AltStyle によって変換されたページ (->オリジナル) /