Permalink
Browse files

Avoid a potential infinite loop when losing sync at EOF.

  • Loading branch information...
1 parent 68bce0e commit cfbe364b1442141775becd6259a4a9634891882e @threedaymonk committed Apr 10, 2011
Showing with 3 additions and 0 deletions.
  1. +3 −0 count-codepoints.c
View
@@ -13,6 +13,7 @@ int32_t read_utf8_codepoint(FILE* fp){
int32_t result, byte, i, j, k;
resync:
+ if (0 != feof(fp)) goto fail;
byte = (int32_t)fgetc(fp);
if (byte < 0x80) return byte;
@@ -28,6 +29,8 @@ int32_t read_utf8_codepoint(FILE* fp){
return result;
}
}
+
+fail:
return -1;
}

0 comments on commit cfbe364

Please sign in to comment.