summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hurst <jhurst@cinecert.com>2021-05-11 13:31:55 -0700
committerGitHub <noreply@github.com>2021-05-11 13:31:55 -0700
commit8c51d30f81cc4a123ec75be93e67cedb48982e40 (patch)
tree2d70b7a0f77d2a62431d8098e15051cbf86a0b0a
parent0efe95e643368c1a88c0bbb2f2c76bc3e764fae1 (diff)
parent519e02618d674a78011b209f3fa5b080855248cb (diff)
Merge pull request #56 from DolbyLaboratories/dolby/fix_misaligned_reads
Fix misaligned reads
-rw-r--r--src/KM_platform.h11
-rwxr-xr-xsrc/MXFTypes.cpp4
2 files changed, 12 insertions, 3 deletions
diff --git a/src/KM_platform.h b/src/KM_platform.h
index defcd8a..3e50e54 100644
--- a/src/KM_platform.h
+++ b/src/KM_platform.h
@@ -64,6 +64,7 @@ typedef long long i64_t;
# endif // KM_WIN32
# include <stdio.h>
+# include <string.h>
# include <assert.h>
# include <stdlib.h>
# include <limits.h>
@@ -135,11 +136,17 @@ namespace Kumu
// read an integer from byte-structured storage
template<class T>
- inline T cp2i(const byte_t* p) { return *(T*)p; }
+ inline T cp2i(const byte_t* p) {
+ T value;
+ memcpy(&value, p, sizeof(T));
+ return value;
+ }
// write an integer to byte-structured storage
template<class T>
- inline void i2p(T i, byte_t* p) { *(T*)p = i; }
+ inline void i2p(T i, byte_t* p) {
+ memcpy(p, &i, sizeof(T));
+ }
# ifdef KM_BIG_ENDIAN
diff --git a/src/MXFTypes.cpp b/src/MXFTypes.cpp
index 72338bb..412f336 100755
--- a/src/MXFTypes.cpp
+++ b/src/MXFTypes.cpp
@@ -286,7 +286,9 @@ ASDCP::MXF::UTF16String::Unarchive(Kumu::MemIOReader* Reader)
for ( ui32_t i = 0; i < length; i++ )
{
- int count = wcrtomb(mb_buf, KM_i16_BE(p[i]), &ps);
+ ui16_t pi;
+ memcpy(&pi, &p[i], sizeof(ui16_t));
+ int count = wcrtomb(mb_buf, KM_i16_BE(pi), &ps);
if ( count == -1 )
{