Skip to content

Commit 9c1fe09

Browse files
committed
Add assertion to detect wrong endianness handling
Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent bf9b72c commit 9c1fe09

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/ccutil/helpers.h

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#ifndef TESSERACT_CCUTIL_HELPERS_H_
2626
#define TESSERACT_CCUTIL_HELPERS_H_
2727

28+
#include <cassert>
2829
#include <stdio.h>
2930
#include <string.h>
3031
#include <functional>
@@ -187,6 +188,7 @@ inline int IntCastRounded(float x) {
187188

188189
// Reverse the order of bytes in a n byte quantity for big/little-endian switch.
189190
inline void ReverseN(void* ptr, int num_bytes) {
191+
assert(num_bytes == 1 || num_bytes == 2 || num_bytes == 4 || num_bytes == 8);
190192
char* cptr = static_cast<char*>(ptr);
191193
int halfsize = num_bytes / 2;
192194
for (int i = 0; i < halfsize; ++i) {

0 commit comments

Comments
 (0)