OBFI

Brainfuck Interpreter
git clone http://git.omkov.net/OBFI
Log | Tree | Refs | README | LICENCE | Download

AuthorJakob Wakeling <[email protected]>
Date2020-08-26 10:26:08
Commit2df50075436668fcfb96d4f86b135d4045520d0d
Parent37f84322bc45b4d334e25dc4da14688c21be9155

Change behaviour on EOF to 0 instead of -1

Diffstat

M README.md | 1 +
M src/obfi.c | 2 +-

2 files changed, 2 insertions, 1 deletions

diff --git a/README.md b/README.md
index cb00937..1a6282b 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@ The OMKOV Brainfuck Interpreter (OBFI) is a minimal Brainfuck interpreter.
 * OBFI uses single octet cells, and arithmetic wraps around.
 * OBFI provides 30000 cells.
 * OBFI does not perform array bound checking.
-* OBFI will set the current cell to EOF when EOF is encountered.
+* OBFI will set the current cell to 0 when EOF is encountered.
 
 ## Optimisations
 
diff --git a/src/obfi.c b/src/obfi.c
index 58a6ebd..9e8bb4f 100644
--- a/src/obfi.c
+++ b/src/obfi.c
@@ -131,7 +131,7 @@ static inline int run(const char *fb, const long *fc) {
 	case 1: { p  += fc[i]; break; }
 	case 2: { *p += fc[i]; break; }
 	case 3: { fputc(*p, stdout); break; }
-	case 4: { *p = fgetc(stdin); break; }
+	case 4: { int c = fgetc(stdin); *p = c != EOF ? c : 0; break; }
 	case 5: { i += !*p ? fc[i] : 0; break; }
 	case 6: { i +=  *p ? fc[i] : 0; break; }
 	case 7: { *p = 0; break; }