Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d548caa

Browse files
committed
use memcpy to avoid misaligned pointer UB
compiles to the same thing before/after at any optimization level
1 parent 6353deb commit d548caa

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

‎src/bmp/BMPParser.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "BMPParser.h"
22

33
#include <cassert>
4+
#include <cstring>
45

56
using namespace std;
67
using namespace BMPParser;
@@ -384,7 +385,8 @@ string Parser::getErrMsg() const{
384385
template <typename T, bool check> inline T Parser::get(){
385386
if(check)
386387
CHECK_OVERRUN(ptr, sizeof(T), T);
387-
T val = *(T*)ptr;
388+
T val;
389+
std::memcpy(&val, ptr, sizeof(T));
388390
ptr += sizeof(T);
389391
return val;
390392
}

0 commit comments

Comments
(0)

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