Convert bitfields to integers in a safe way.
This is commit eb391c52ee redone, but without the
non-standard anonymous union.
This commit is contained in:
parent
9b394bc887
commit
81afa26e4a
4 changed files with 11 additions and 2 deletions
|
|
@ -100,3 +100,10 @@ const char *winerror(int err) {
|
|||
}
|
||||
#endif
|
||||
|
||||
unsigned int bitfield_to_int(void *bitfield, size_t size) {
|
||||
unsigned int value = 0;
|
||||
if(size > sizeof value)
|
||||
size = sizeof value;
|
||||
memcpy(&value, bitfield, size);
|
||||
return value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,4 +43,6 @@ extern const char *winerror(int);
|
|||
#define strerror(x) ((x)>0?strerror(x):winerror(GetLastError()))
|
||||
#endif
|
||||
|
||||
extern unsigned int bitfield_to_int(void *bitfield, size_t size);
|
||||
|
||||
#endif /* __TINC_UTILS_H__ */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue