summaryrefslogtreecommitdiff
path: root/fofi
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2018-05-24 20:15:42 +0200
committerAlbert Astals Cid <aacid@kde.org>2018-05-24 20:15:42 +0200
commit07318f3899248f67a58148b29a9555ff47a1b083 (patch)
treeb349ac2a178769cdcb289ac9cf668f1dbf7ed23e /fofi
parent6b91d37a704fb2b6fa9529d859c366c331327ab9 (diff)
StreamReader::cmp: Fix potential undefined behaviour
going outside an array range is technically undefined behaviour, even if then after you go back in range with the next operation, so we first calculate the diff and then add it to the array
Diffstat (limited to 'fofi')
-rw-r--r--fofi/FoFiIdentifier.cc7
1 files changed, 3 insertions, 4 deletions
diff --git a/fofi/FoFiIdentifier.cc b/fofi/FoFiIdentifier.cc
index 3d41145b..ffe9c47c 100644
--- a/fofi/FoFiIdentifier.cc
+++ b/fofi/FoFiIdentifier.cc
@@ -378,13 +378,12 @@ GBool StreamReader::getUVarBE(int pos, int size, Guint *val) {
}
GBool StreamReader::cmp(int pos, const char *s) {
- int n;
-
- n = (int)strlen(s);
+ const int n = (int)strlen(s);
if (!fillBuf(pos, n)) {
return gFalse;
}
- return !memcmp(buf - bufPos + pos, s, n);
+ const int posDiff = pos - bufPos;
+ return !memcmp(buf + posDiff, s, n);
}
GBool StreamReader::fillBuf(int pos, int len) {