Index: pwsafe.cpp =================================================================== RCS file: /cvsroot/pwsafe/pwsafe/pwsafe.cpp,v retrieving revision 1.56 retrieving revision 1.57 diff -u -r1.56 -r1.57 --- pwsafe.cpp 30 Sep 2005 10:30:56 -0000 1.56 +++ pwsafe.cpp 12 Aug 2007 12:33:06 -0000 1.57 @@ -3,7 +3,7 @@ Copyright (C) 2004-2005 Nicolas S. Dade - $Id: pwsafe-0.2.0-cvs-1.57.patch,v 1.1 2011/04/13 08:43:49 nirbheek Exp $ + $Id: pwsafe-0.2.0-cvs-1.57.patch,v 1.1 2011/04/13 08:43:49 nirbheek Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -3346,6 +3346,12 @@ } bufpos += rc; + buf[bufpos] = '\0'; + + if (rc == 0) { + // EOF (ctrl-D) + break; + } if (bufpos == buflen && !strchr(buf,'\n')) { // we needed a bigger buffer @@ -3354,6 +3360,7 @@ fprintf(stderr, "Error: %s out of memory\n", program_name); memset(buf,0,buflen); free(buf); + throw FailEx(); } memcpy(new_buf, buf, bufpos); @@ -3364,9 +3371,15 @@ } } - int len = strchr(buf,'\n') - buf; - saved.assign(buf+len+1, bufpos-(len+1)); - buf[len] = '\0'; + char* lf = strchr(buf,'\n'); + if (lf) { + // save the rest of the input for later + saved.assign(lf+1); + *lf = '\0'; + } else { + saved.assign("",0); + } + return buf; } #endif // WITH_READLINE