Skip to content

Commit 0bdae8f

Browse files
committed
GENERIC_2D_ARRAY: Fix runtime error in assignment operator
Instrumented code throws this runtime error during OCR: ../../src/ccstruct/matrix.h:84:11: runtime error: null pointer passed as argument 2, which is declared to never be null Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent bee874a commit 0bdae8f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/ccstruct/matrix.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ class GENERIC_2D_ARRAY {
8181

8282
void operator=(const GENERIC_2D_ARRAY<T>& src) {
8383
ResizeNoInit(src.dim1(), src.dim2());
84-
memcpy(array_, src.array_, num_elements() * sizeof(array_[0]));
84+
int size = num_elements();
85+
if (size > 0) {
86+
memcpy(array_, src.array_, size * sizeof(array_[0]));
87+
}
8588
}
8689

8790
// Reallocates the array to the given size. Does not keep old data, but does

0 commit comments

Comments
 (0)