diff --git a/liblouis/transcommon.ci b/liblouis/transcommon.ci
--- a/liblouis/transcommon.ci
+++ b/liblouis/transcommon.ci
@@ -280,7 +280,7 @@
{
int k;
int kk = passSrc;
- for (k = passIC + 2; k < passIC + 2 + passInstructions[passIC + 1]; k++)
+ for (k = passIC + 2; k < passIC + 2 + passInstructions[passIC + 1] && kk < srcmax; k++)
if (currentInput[kk] == ENDSEGMENT || passInstructions[k] !=
currentInput[kk++])
return 0;