Description: Replace gets with readline Author: Jörg Frings-Fürst Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=841626 Last-Update: 2016-10-22 --- This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ Index: trunk/bin/dbfutil1.cpp =================================================================== --- trunk.orig/bin/dbfutil1.cpp +++ trunk/bin/dbfutil1.cpp @@ -38,6 +38,7 @@ */ #include +#include // next lines are helpful for debugging purposes /* @@ -153,11 +154,18 @@ void MyClass::FilterMenu() /************************************************************************/ void MyClass::SetFilter() { - char Expression[512]; - memset( Expression, 0x00, 512 ); + /* replace getc with getline */ + + constexpr int SIZE = 512; + + char Expression[SIZE]; + memset( Expression, 0x00, SIZE ); while( !strlen( Expression )){ std::cout << "Enter filter expression (like AMOUNT<5)" << std::endl; - gets( Expression ); +/* gets( Expression );*/ + std::cin.getline(Expression, SIZE-1); + Expression[SIZE-1] = '\0'; + std::cin.ignore(std::numeric_limits::max(), '\n'); } if( xbf ) delete xbf; @@ -235,19 +243,27 @@ void MyClass::LastFilterRec() #ifdef XB_EXPRESSIONS void MyClass::ProcessExpression() { - char exprsn[256]; + /* replace getc with getline */ + + constexpr int SIZE = 256; + + char exprsn[SIZE]; char type; xbExpn *exp; // expression xbShort rc; int debug = 0; - memset( exprsn, 0x00, 256 ); + memset( exprsn, 0x00, SIZE ); std::cout << "Enter expression string or HELP" << std::endl; while( !strstr( exprsn, "QUIT" ) && !strstr( exprsn, "quit" )){ std::cout << ">"; - gets( exprsn ); +/* gets( exprsn ); */ + + std::cin.getline(exprsn, SIZE-1); + exprsn[SIZE-1] = '\0'; + std::cin.ignore(std::numeric_limits::max(), '\n'); if( strstr( exprsn, "HELP" ) || strstr( exprsn, "help" )){ std::cout << "** Command Help ***" << std::endl << std::endl;