[IBPP-DISCUSS] another bug, crashes app in debug mode with IBPP_WINDOWS defined
IBPP is a C++ client class library for FirebirdSQL
Status: Inactive
Brought to you by:
epocman
From: Val S. <ib...@di...> - 2004-02-12 11:18:07
|
Olivier, In `StatementImpl::Prepare` you have `DebugOutput("Prepare(\"%s\")", sql.c_str());` and `DebugOutput` is defined as ============================================== void DebugOutput(const char* format, ...) { #ifdef IBPP_WINDOWS if (format != 0) { char buffer[1024] = "IBPP: "; // 6 prefix characters va_list argptr; va_start(argptr, format); vsprintf(&buffer[6], format, argptr); // 6, see above va_end(argptr); ::OutputDebugString(buffer); } else ::OutputDebugString("IBPP: Calling DebugOutput(0) !"); #endif } ============================================== Which results in all sorts of nasty errors, when sql.size() > 1017, which I have been experiencing and trying to locate the source, since the yesterday morning. The errors were nasty indeed, and debugger wasn't showing, where exactly the problem is occurring. Possible solutions: 1. Replace ugly `vsprintf` (aka "overflow my buffer") with `vsnprintf` which lets you set the max buffer size. 2. Get rid of the error prone `vsprintf` and redefine `DebugOutput` as: void DebugOutput(const std::string& message) { #ifdef IBPP_WINDOWS ::OutputDebugString(message.c_str()); #endif } Then, you can call it as std::stringstream message; message<<"Some text - "<<int_value<<" and "<<somethingelse<<std::endl; DebugOutput(message.str()); Which I think is much less error prone than `vs*printf` and is more readable. ------------- In any case, one way or another, this problem has to be solved. For now, I have commented out the `DebugOutput("Prepare(\"%s\")", sql.c_str());` call. Regards, Val Samko |