SHA256
1
0
forked from pool/gap
gap/gap-typepuns.diff

85 lines
2.6 KiB
Diff

parent f01d2b07a7a668e6b27b9527e070d8315c084d6e ()
commit 9316710832a9f6d582e1dcf3b9645e9efc8efc8f
Author: Jan Engelhardt <jengelh@medozas.de>
Date: Sun Jun 26 11:42:56 2011 +0200
src: fix undefined behavior in copy operations
---
src/gap.c | 4 ++--
src/saveload.c | 6 ++++--
src/streams.c | 4 ++--
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/gap.c b/src/gap.c
index 06fc308..a95b1d5 100644
--- a/src/gap.c
+++ b/src/gap.c
@@ -1891,7 +1891,7 @@ Obj FuncCOM_FILE (
Pr( "#I READ_GAP_ROOT: loading '%s' dynamically\n",
(Int)CSTR_STRING(filename), 0L );
}
- info = *(StructInitInfo**)result;
+ memcpy(&info, result, sizeof(info));
res = info->initKernel(info);
UpdateCopyFopyInfo();
res = res || info->initLibrary(info);
@@ -1909,7 +1909,7 @@ Obj FuncCOM_FILE (
Pr( "#I READ_GAP_ROOT: loading '%s' statically\n",
(Int)CSTR_STRING(filename), 0L );
}
- info = *(StructInitInfo**)result;
+ memcpy(&info, result, sizeof(info));
res = info->initKernel(info);
UpdateCopyFopyInfo();
res = res || info->initLibrary(info);
diff --git a/src/saveload.c b/src/saveload.c
index 52dc82d..2e2d55a 100644
--- a/src/saveload.c
+++ b/src/saveload.c
@@ -452,7 +452,7 @@ void SaveDouble( Double d)
{
UInt i;
UInt1 buf[sizeof(Double)];
- *(Double *)buf = d;
+ memcpy(buf, &d, sizeof(d));
for (i = 0; i < sizeof(Double); i++)
SAVE_BYTE(buf[i]);
}
@@ -461,9 +461,11 @@ Double LoadDouble( void)
{
UInt i;
UInt1 buf[sizeof(Double)];
+ Double d;
for (i = 0; i < sizeof(Double); i++)
buf[i] = LOAD_BYTE();
- return *(Double *)buf;
+ memcpy(&d, buf, sizeof(d));
+ return d;
}
/***************************************************************************
diff --git a/src/streams.c b/src/streams.c
index e91cd92..3091fb9 100644
--- a/src/streams.c
+++ b/src/streams.c
@@ -353,7 +353,7 @@ Int READ_GAP_ROOT ( Char * filename )
Pr( "#I READ_GAP_ROOT: loading '%s' dynamically\n",
(Int)filename, 0L );
}
- info = *(StructInitInfo**)result;
+ memcpy(&info, result, sizeof(info));
res = info->initKernel(info);
if (!SyRestoring) {
UpdateCopyFopyInfo();
@@ -374,7 +374,7 @@ Int READ_GAP_ROOT ( Char * filename )
Pr( "#I READ_GAP_ROOT: loading '%s' statically\n",
(Int)filename, 0L );
}
- info = *(StructInitInfo**)result;
+ memcpy(&info, result, sizeof(info));
res = info->initKernel(info);
if (!SyRestoring) {
UpdateCopyFopyInfo();
--
# Created with git-export-patch