From 32ca60e9518b79ee9921c834eb30e425a45f6020 Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Sat, 16 Sep 2017 18:02:45 +0100 Subject: [PATCH] Fix cvs handling hangup on -funsigned-char platforms The bug csv01.test hangs on powerpc32 and powerpc64 (both are 'char' == 'unsigned char' platforms) Hangup happens in static int csvtabNext(sqlite3_vtab_cursor *cur){ ... if( z==0 || pCur->rdr.cTerm==EOF ){ Here 'pCur->rdr.cTerm' is of type 'char' (holds truncated EOF) while EOF constant is (int)(-1). On 'signed char' platforms both arguments sign-extend to 'int' before comparison and test "works". But ont on 'unsigned char' platforms where comparison is '0xff == -1'. Workaround by trunacting EOF constant down to 'char' size. Not an ideal fix but makes EOF handling more consistent. Reported-by: Matt Turner Bug: https://bugs.gentoo.org/630698 Signed-off-by: Sergei Trofimovich --- ext/misc/csv.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ext/misc/csv.c b/ext/misc/csv.c index 6d99634..1bd9888 100644 --- a/ext/misc/csv.c +++ b/ext/misc/csv.c @@ -686,7 +686,13 @@ static int csvtabNext(sqlite3_vtab_cursor *cur){ pCur->aLen[i] = 0; i++; } - if( z==0 || pCur->rdr.cTerm==EOF ){ + /* + * HACK: truncate EOF to 'char' to make code + * work equally (bad) on systems with signed + * and unsigned char. Other wise platforms + * with unsigned char loop indefinitely here. + */ + if( z==0 || pCur->rdr.cTerm==(char)EOF ){ pCur->iRowid = -1; }else{ pCur->iRowid++; -- 2.14.1