8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 22:43:04 +01:00

Misc, style, fixing dangerous warnings, constness, etc.

This commit is contained in:
robocop 2009-02-08 11:23:46 +00:00
parent 3893f85902
commit a18dc0519f
32 changed files with 496 additions and 421 deletions

View File

@ -804,7 +804,7 @@ SINT64 query_performance_counter()
return static_cast<SINT64>(tp.tv_sec) * BILLION + tp.tv_nsec;
#else
// This is not safe because of possible wrapping and very inprecise
// This is not safe because of possible wrapping and very imprecise
return clock();
#endif
}
@ -828,7 +828,7 @@ SINT64 query_performance_frequency()
return BILLION;
#else
// This is not safe because of possible wrapping and very inprecise
// This is not safe because of possible wrapping and very imprecise
return CLOCKS_PER_SEC;
#endif
}

View File

@ -507,10 +507,7 @@ ISC_STATUS DSQL_fetch(thread_db* tdbb,
const dsql_par* const eof = request->req_eof;
bool eof_reached = false;
if (eof) {
eof_reached = !*((USHORT *) eof->par_desc.dsc_address);
}
const bool eof_reached = eof && !*((USHORT*) eof->par_desc.dsc_address);
if (eof_reached)
{
@ -2572,14 +2569,20 @@ static dsql_req* prepare(thread_db* tdbb, dsql_dbb* database, jrd_tra* transacti
if (!node)
return statement;
statement->req_traced =
statement->req_type != REQ_COMMIT &&
statement->req_type != REQ_COMMIT_RETAIN &&
statement->req_type != REQ_ROLLBACK &&
statement->req_type != REQ_ROLLBACK_RETAIN &&
statement->req_type != REQ_GET_SEGMENT &&
statement->req_type != REQ_PUT_SEGMENT &&
statement->req_type != REQ_START_TRANS;
switch (statement->req_type)
{
case REQ_COMMIT:
case REQ_COMMIT_RETAIN:
case REQ_ROLLBACK:
case REQ_ROLLBACK_RETAIN:
case REQ_GET_SEGMENT:
case REQ_PUT_SEGMENT:
case REQ_START_TRANS:
statement->req_traced = false;
break;
default:
statement->req_traced = true;
}
// stop here for statements not requiring code generation

View File

@ -62,11 +62,11 @@ namespace Jrd
PIO_get_unique_file_id(pageSpace->file, buffer);
Firebird::string file_id;
char* s = file_id.getBuffer(2 * buffer.getCount());
for (size_t i = 0; i < buffer.getCount(); i++)
{
TEXT hex[3];
sprintf(hex, "%02x", (int) buffer[i]);
file_id.append(hex);
sprintf(s, "%02x", (int) buffer[i]);
s += 2;
}
return file_id;

View File

@ -34,7 +34,7 @@ GlobalPtr<RuntimeStatistics> RuntimeStatistics::dummy;
#ifdef REL_COUNTS_TREE
void RuntimeStatistics::bumpValue(StatType index, SLONG relation_id)
void RuntimeStatistics::bumpValue(const StatType index, SLONG relation_id)
{
fb_assert(index >= 0);
++relChgNumber;
@ -77,11 +77,14 @@ void RuntimeStatistics::addRelCounts(const RelCounters& other, bool add)
RelationCounts& dst = first.current();
fb_assert(src.rlc_relation_id == dst.rlc_relation_id);
for (int index = 0; index < FB_NELEM(src.rlc_counter); index++)
{
if (add)
{
for (int index = 0; index < FB_NELEM(src.rlc_counter); index++)
dst.rlc_counter[index] += src.rlc_counter[index];
}
else
{
for (int index = 0; index < FB_NELEM(src.rlc_counter); index++)
dst.rlc_counter[index] -= src.rlc_counter[index];
}
} while(second.getNext());
@ -210,11 +213,14 @@ void RuntimeStatistics::addRelCounts(const RelCounters& other, bool add)
RelationCounts* dst = &(rel_counts[pos]);
fb_assert(dst->rlc_relation_id == src->rlc_relation_id);
for (int index = 0; index < FB_NELEM(src->rlc_counter); index++)
{
if (add)
{
for (int index = 0; index < FB_NELEM(src->rlc_counter); index++)
dst->rlc_counter[index] += src->rlc_counter[index];
}
else
{
for (int index = 0; index < FB_NELEM(src->rlc_counter); index++)
dst->rlc_counter[index] -= src->rlc_counter[index];
}
}

View File

@ -84,7 +84,7 @@ public:
TOTAL_ITEMS // last
};
RuntimeStatistics(MemoryPool& pool) : rel_counts(pool)
explicit RuntimeStatistics(MemoryPool& pool) : rel_counts(pool)
{
reset();
}
@ -120,7 +120,7 @@ public:
++allChgNumber;
}
void bumpValue(StatType index, SLONG relation_id);
void bumpValue(const StatType index, SLONG relation_id);
// Calculate difference between counts stored in this object and current
// counts of given request. Counts stored in object are destroyed.
@ -153,7 +153,7 @@ public:
}
// copy counters values from other instance
// after copying both instances is "in-sync" i.e. have the same
// after copying both instances are "in-sync" i.e. have the same
// allChgNumber and relChgNumber values
RuntimeStatistics& assign(const RuntimeStatistics& other)
{

View File

@ -457,7 +457,7 @@ public:
{
if (m_options->dpb_user_name.empty())
return m_options->dpb_trusted_login.c_str();
else
return m_options->dpb_user_name.c_str();
}

View File

@ -902,7 +902,7 @@ static THREAD_ENTRY_DECLARE svcShutdownThread(THREAD_ENTRY_PARAM)
void Service::detach()
{
// save it cause after call to finish() we can't access class members any more
bool localDoShutdown = svc_do_shutdown;
const bool localDoShutdown = svc_do_shutdown;
if (svc_uses_security_database)
{

View File

@ -168,7 +168,7 @@ public: // external interface with service
{
if (svc_username.empty())
return svc_trusted_login;
else
return svc_username;
}

View File

@ -55,7 +55,7 @@ static void usage(UtilSvc* uSvc, const char* message, ...)
"Actions: \n"
" -STA[RT] Start trace session\n"
" -STO[P] Stop trace session\n"
" -S[USPEND] Susupend trace session\n"
" -S[USPEND] Suspend trace session\n"
" -R[ESUME] Resume trace session\n"
" -L[IST] List existing trace sessions\n\n"
"Parameters: \n"
@ -143,11 +143,11 @@ static const in_sw_tab_t* findSwitch(const in_sw_tab_t* table, string sw)
const char* TRACE_ERR_CONFLICT_ACTS = "conflicting actions \"%s\" and \"%s\" found";
const char* TRACE_ERR_ACT_NOTFOUND = "action switch not found";
const char* TRACE_ERR_SWITCH_ONCE = "switch \"%s\" must be set only once";
const char* TRACE_ERR_PARAM_VAL_MISS = "value for switch \"%s\" is missed";
const char* TRACE_ERR_PARAM_VAL_MISS = "value for switch \"%s\" is missing";
const char* TRACE_ERR_PARAM_INVALID = "invalid value (\"%s\") for switch \"%s\"";
const char* TRACE_ERR_SWITCH_UNKNOWN = "unknow switch \"%s\" encountered";
const char* TRACE_ERR_SWITCH_UNKNOWN = "unknown switch \"%s\" encountered";
const char* TRACE_ERR_SWITCH_SVC_ONLY = "switch \"%s\" can be used by service only";
const char* TRACE_ERR_SWITCH_PARAM_MISS = "mandatory parameter \"%s\" for switch \"%s\" is missed";
const char* TRACE_ERR_SWITCH_PARAM_MISS = "mandatory parameter \"%s\" for switch \"%s\" is missing";
const char* TRACE_ERR_PARAM_ACT_NOTCOMPAT = "parameter \"%s\" is incompatible with action \"%s\"";

View File

@ -196,7 +196,7 @@ void ConfigStorage::checkFile()
{
fseek(cfgFile, 0, SEEK_SET);
char* p = session.ses_config.getBuffer(len + 1);
if (fread(p, 1, len, cfgFile) != len)
if (fread(p, 1, len, cfgFile) != size_t(len))
{
Arg::Gds temp(isc_io_error);
temp << Arg::Str("fopen") << Arg::Str(configFileName.c_str());
@ -375,7 +375,11 @@ void ConfigStorage::removeSession(ULONG id)
setDirty();
currID = 0;
lseek(m_cfg_file, -len, SEEK_CUR);
// Do not delete this temporary signed var, otherwise we get
// warning C4146: unary minus operator applied to unsigned type, result still unsigned
// but we need a negative offset here.
const long local_len = len;
lseek(m_cfg_file, -local_len, SEEK_CUR);
write(m_cfg_file, &currID, len);
break;
}

View File

@ -151,7 +151,7 @@ public:
class StorageGuard
{
public:
StorageGuard(ConfigStorage* storage) :
explicit StorageGuard(ConfigStorage* storage) :
m_storage(storage)
{
m_storage->acquire();

View File

@ -47,7 +47,7 @@ public:
m_start_clock = fb_utils::query_performance_counter();
static char empty_string[] = "";
static const char empty_string[] = "";
if (!m_string_len || !string)
{
m_string = empty_string;
@ -95,7 +95,7 @@ public:
private:
bool m_need_trace;
Attachment* m_attachment;
Attachment* const m_attachment;
dsql_req* m_request;
SINT64 m_start_clock;
size_t m_string_len;
@ -164,8 +164,8 @@ public:
private:
bool m_need_trace;
Attachment* m_attachment;
dsql_req* m_request;
Attachment* const m_attachment;
dsql_req* const m_request;
SINT64 m_start_clock;
};
@ -216,8 +216,8 @@ public:
private:
bool m_need_trace;
Attachment* m_attachment;
dsql_req* m_request;
Attachment* const m_attachment;
dsql_req* const m_request;
SINT64 m_start_clock;
};

View File

@ -78,9 +78,9 @@ public:
private:
bool m_need_trace;
bool m_commit;
bool m_retain;
jrd_tra* m_transaction;
const bool m_commit;
const bool m_retain;
jrd_tra* const m_transaction;
SINT64 m_start_clock;
Firebird::AutoPtr<RuntimeStatistics> m_baseline;
};
@ -156,8 +156,8 @@ public:
private:
bool m_need_trace;
thread_db* m_tdbb;
jrd_req* m_request;
thread_db* const m_tdbb;
jrd_req* const m_request;
SINT64 m_start_clock;
};
@ -213,8 +213,8 @@ public:
private:
bool m_need_trace;
thread_db* m_tdbb;
jrd_req* m_request;
thread_db* const m_tdbb;
jrd_req* const m_request;
SINT64 m_start_clock;
};
@ -278,10 +278,10 @@ public:
private:
bool m_need_trace;
thread_db* m_tdbb;
jrd_req* m_request;
thread_db* const m_tdbb;
jrd_req* const m_request;
SINT64 m_start_clock;
int m_which_trig;
const int m_which_trig;
};
@ -342,10 +342,10 @@ public:
private:
bool m_need_trace;
thread_db* m_tdbb;
thread_db* const m_tdbb;
SINT64 m_start_clock;
size_t m_blr_length;
const SCHAR* m_blr;
const size_t m_blr_length;
const SCHAR* const m_blr;
};
@ -406,8 +406,8 @@ public:
private:
bool m_need_trace;
thread_db* m_tdbb;
jrd_req* m_request;
thread_db* const m_tdbb;
jrd_req* const m_request;
SINT64 m_start_clock;
};
@ -457,10 +457,10 @@ public:
private:
bool m_need_trace;
thread_db* m_tdbb;
thread_db* const m_tdbb;
SINT64 m_start_clock;
size_t m_ddl_length;
const SCHAR* m_ddl;
const size_t m_ddl_length;
const SCHAR* const m_ddl;
};
} // namespace Jrd

View File

@ -144,7 +144,7 @@ size_t TraceLogImpl::read(void* buf, size_t size)
const off_t len = lseek(m_fileHandle, 0, SEEK_CUR);
if (len >= MAX_LOG_FILE_SIZE)
{
// this file was reads completely, go to next one
// this file was read completely, go to next one
::close(m_fileHandle);
removeFile(m_fileNum);
@ -193,7 +193,7 @@ size_t TraceLogImpl::write(const void* buf, size_t size)
if (!toWrite)
{
// While this instance of writer was idle, new log file was created.
// More, if current file was already readed by reader, we must delete it.
// More, if current file was already read by reader, we must delete it.
::close(m_fileHandle);
if (m_fileNum < m_base->readFileNum) {
removeFile(m_fileNum);
@ -204,6 +204,8 @@ size_t TraceLogImpl::write(const void* buf, size_t size)
}
const int written = ::write(m_fileHandle, p, toWrite);
if (written == -1 || size_t(written) != toWrite)
system_call_failed::raise("write", errno);
p += toWrite;
writeLeft -= toWrite;

View File

@ -85,18 +85,18 @@ friend class TraceLogGuard;
class TraceLogGuard
{
public:
TraceLogGuard(TraceLogImpl* log) : m_log(log)
explicit TraceLogGuard(TraceLogImpl* log) : m_log(*log)
{
m_log->lock();
m_log.lock();
}
~TraceLogGuard()
{
m_log->unlock();
m_log.unlock();
}
private:
TraceLogImpl* m_log;
TraceLogImpl& m_log;
};

View File

@ -79,11 +79,11 @@ bool TraceManager::check_result(const TracePlugin* plugin, const char* module, c
return false;
}
TraceManager::TraceManager(Attachment* _att) :
attachment(_att),
TraceManager::TraceManager(Attachment* in_att) :
attachment(in_att),
service(NULL),
filename(NULL),
trace_sessions(*_att->att_pool)
trace_sessions(*in_att->att_pool)
{
change_number = 0;
@ -91,11 +91,11 @@ TraceManager::TraceManager(Attachment* _att) :
load_modules();
}
TraceManager::TraceManager(Service* _svc) :
TraceManager::TraceManager(Service* in_svc) :
attachment(NULL),
service(_svc),
service(in_svc),
filename(NULL),
trace_sessions(_svc->getPool())
trace_sessions(in_svc->getPool())
{
change_number = 0;
@ -103,10 +103,10 @@ TraceManager::TraceManager(Service* _svc) :
load_modules();
}
TraceManager::TraceManager(const char* _filename) :
TraceManager::TraceManager(const char* in_filename) :
attachment(NULL),
service(NULL),
filename(_filename),
filename(in_filename),
trace_sessions(*getDefaultMemoryPool())
{
change_number = 0;
@ -145,7 +145,7 @@ void TraceManager::load_modules()
while (plugins.next())
{
PathName modLib(plugins.getFileName());
const PathName modLib(plugins.getFileName());
if (modLib.find(NTRACE_PREFIX) == PathName::npos)
continue;

View File

@ -49,9 +49,9 @@ class TraceManager
{
public:
/* Initializes plugins. */
TraceManager(Attachment* att);
TraceManager(Service* svc);
TraceManager(const char* filename);
explicit TraceManager(Attachment* in_att);
explicit TraceManager(Service* in_svc);
explicit TraceManager(const char* in_filename);
/* Finalize plugins. Called when database is closed by the engine */
~TraceManager();

View File

@ -199,7 +199,7 @@ int TraceSQLStatementImpl::getStmtID()
{
if (m_stmt->req_request)
return m_stmt->req_request->req_id;
else
return 0;
}
@ -216,7 +216,7 @@ const char* TraceSQLStatementImpl::getPlan()
m_plan = &buff;
const int len = DSQL_get_plan_info(JRD_get_thread_data(),
const_cast<dsql_req*> (m_stmt), sizeof(buff), &m_plan);
const_cast<dsql_req*>(m_stmt), sizeof(buff), &m_plan);
if (len)
m_plan[len] = 0;
@ -326,14 +326,14 @@ void TraceProcedureImpl::JrdParamsImpl::fillParams()
dsc* from_desc = NULL;
dsc desc;
jrd_nod* const prm = (*ptr)->nod_arg[e_asgn_to];
const jrd_nod* const prm = (*ptr)->nod_arg[e_asgn_to];
switch (prm->nod_type)
{
case nod_argument:
{
impure_value* impure = (impure_value*) ((SCHAR *) m_request + prm->nod_impure);
jrd_nod* message = prm->nod_arg[e_arg_message];
Format* format = (Format*) message->nod_arg[e_msg_format];
//const impure_value* impure = (impure_value*) ((SCHAR *) m_request + prm->nod_impure);
const jrd_nod* message = prm->nod_arg[e_arg_message];
const Format* format = (Format*) message->nod_arg[e_msg_format];
const int arg_number = (int) (IPTR) prm->nod_arg[e_arg_number];
desc = format->fmt_desc[arg_number];
@ -343,7 +343,7 @@ void TraceProcedureImpl::JrdParamsImpl::fillParams()
// handle null flag if present
if (prm->nod_arg[e_arg_flag])
{
dsc* flag = EVL_expr(tdbb, prm->nod_arg[e_arg_flag]);
const dsc* flag = EVL_expr(tdbb, prm->nod_arg[e_arg_flag]);
if (MOV_get_long(flag, 0)) {
from_desc->dsc_flags |= DSC_null;
}

View File

@ -65,7 +65,7 @@ public:
virtual const char* getRemoteProcessName();
private:
const Attachment* m_att;
const Attachment* const m_att;
};
@ -84,8 +84,8 @@ public:
virtual PerformanceInfo* getPerf() { return m_perf; }
private:
const jrd_tra* m_tran;
PerformanceInfo* m_perf;
const jrd_tra* const m_tran;
PerformanceInfo* const m_perf;
};
@ -105,8 +105,8 @@ public:
private:
static void print_dyn(void* arg, SSHORT offset, const char* line);
const char* m_ddl;
size_t m_length;
const char* const m_ddl;
const size_t m_length;
Firebird::string m_text;
};
@ -127,8 +127,8 @@ public:
private:
static void print_blr(void* arg, SSHORT offset, const char* line);
const char* m_blr;
size_t m_length;
const char* const m_blr;
const size_t m_length;
Firebird::string m_text;
};
@ -146,8 +146,8 @@ public:
virtual PerformanceInfo* getPerf() { return m_perf; }
private:
const jrd_req* m_stmt;
PerformanceInfo* m_perf;
const jrd_req* const m_stmt;
PerformanceInfo* const m_perf;
};
@ -200,8 +200,8 @@ private:
Firebird::HalfStaticArray<dsc, 16> m_descs;
};
const dsql_req* m_stmt;
PerformanceInfo* m_perf;
const dsql_req* const m_stmt;
PerformanceInfo* const m_perf;
char* m_plan;
DSQLParamsImpl m_inputs;
};
@ -239,9 +239,9 @@ public:
virtual const char* getVarValue() { return m_value; }
private:
const char* m_namespace;
const char* m_name;
const char* m_value;
const char* const m_namespace;
const char* const m_name;
const char* const m_value;
};
class TraceProcedureImpl : public TraceProcedure
@ -278,8 +278,8 @@ private:
Firebird::HalfStaticArray<dsc, 16> m_descs;
};
const jrd_req* m_request;
PerformanceInfo* m_perf;
const jrd_req* const m_request;
PerformanceInfo* const m_perf;
JrdParamsImpl m_inputs;
};
@ -300,9 +300,9 @@ public:
virtual PerformanceInfo* getPerf() { return m_perf; }
private:
const jrd_req* m_trig;
SSHORT m_which;
PerformanceInfo* m_perf;
const jrd_req* const m_trig;
const SSHORT m_which;
PerformanceInfo* const m_perf;
};
@ -325,7 +325,7 @@ public:
virtual const char* getRemoteProcessName();
private:
const Service* m_svc;
const Service* const m_svc;
};
@ -351,9 +351,9 @@ public:
const char* filename) :
m_session(session),
m_trace_conn(att),
m_filename(filename)
m_filename(filename),
m_attachment(att)
{
m_attachment = att;
if (m_attachment && !m_attachment->att_filename.empty()) {
m_filename = m_attachment->att_filename.c_str();
}
@ -370,7 +370,7 @@ public:
{
if (m_attachment)
return &m_trace_conn;
else
return NULL;
}
@ -378,10 +378,10 @@ public:
private:
const Firebird::TraceSession& m_session;
const Attachment* m_attachment;
TraceLogWriter* m_logWriter;
TraceConnectionImpl m_trace_conn;
const char* m_filename;
const Attachment* const m_attachment;
};

View File

@ -48,7 +48,7 @@ using namespace Jrd;
class TraceSvcJrd : public TraceSvcIntf
{
public:
TraceSvcJrd(Service& svc) :
explicit TraceSvcJrd(Service& svc) :
m_svc(svc),
m_admin(false),
m_chg_number(0)
@ -269,7 +269,6 @@ void TraceSvcJrd::readSession(TraceSession& session)
TraceManager* mgr = m_svc.getTraceManager();
ConfigStorage* storage = mgr->getStorage();
const size_t maxLogSize = Config::getMaxUserTraceLogSize(); // in MB
bool logFull = false;
if (session.ses_logfile.empty())
{
@ -280,6 +279,7 @@ void TraceSvcJrd::readSession(TraceSession& session)
MemoryPool& pool = *getDefaultMemoryPool();
AutoPtr<TraceLogImpl> log(FB_NEW(pool) TraceLogImpl(pool, session.ses_logfile, true));
bool logFull = false;
UCHAR buff[1024];
while (!m_svc.finished() && checkAlive(session.ses_id))
{
@ -288,7 +288,7 @@ void TraceSvcJrd::readSession(TraceSession& session)
{
if (!checkAlive(session.ses_id))
break;
else
THD_sleep(250);
}
else

View File

@ -43,7 +43,7 @@ const int trs_log_full = 0x0008; // session trace log is full
class TraceSession
{
public:
TraceSession(MemoryPool& pool) :
explicit TraceSession(MemoryPool& pool) :
ses_id(0),
ses_name(pool),
ses_user(pool),

View File

@ -142,9 +142,11 @@ bool putFileFromArgument(char**& av, ClumpletWriter& spb, unsigned int tag)
fseek(file, 0, SEEK_SET);
if (fread(p, 1, len, file) != len) {
fclose(file);
(Arg::Gds(isc_fbsvcmgr_fp_read) << *av << Arg::OsError()).raise();
}
fclose(file);
spb.insertBytes(tag, p, len);
++av;
@ -838,7 +840,7 @@ int main(int ac, char** av)
if (spbItems.getBufferLength() > 0)
{
char send[] = {isc_info_svc_timeout, 2, 0, 1, 0, 0, 0, isc_info_end};
const char send[] = {isc_info_svc_timeout, 2, 0, 1, 0, 0, 0, isc_info_end};
char results[maxbuf];
UserPrint up;

View File

@ -60,7 +60,7 @@ private:
bool parseBoolean(const Firebird::string& value) const;
ULONG parseUInteger(const Firebird::string& value) const;
const char* m_text;
const char* const m_text;
const Firebird::PathName& m_databaseName;
regmatch_t m_subpatterns[10];
TracePluginConfig& m_config;

View File

@ -195,12 +195,12 @@ void TracePluginImpl::rotateLog(size_t added_bytes_length)
{
WriteLockGuard lock(renameLock);
Firebird::TimeStamp stamp(Firebird::TimeStamp::getCurrentTimeStamp());
const Firebird::TimeStamp stamp(Firebird::TimeStamp::getCurrentTimeStamp());
struct tm times;
stamp.decode(&times);
Firebird::PathName newName;
size_t last_dot_pos = config.log_filename.rfind(".");
const size_t last_dot_pos = config.log_filename.rfind(".");
if (last_dot_pos > 0)
{
Firebird::PathName log_name = config.log_filename.substr(0, last_dot_pos);
@ -236,7 +236,7 @@ void TracePluginImpl::logRecord(const char* action, string& line)
{
// We use atomic file appends for logging. Do not try to break logging
// to multiple separate file operations
Firebird::TimeStamp stamp(Firebird::TimeStamp::getCurrentTimeStamp());
const Firebird::TimeStamp stamp(Firebird::TimeStamp::getCurrentTimeStamp());
struct tm times;
stamp.decode(&times);
@ -372,7 +372,7 @@ void TracePluginImpl::logRecordStmt(const char* action, TraceConnection* connect
StatementsTree::Accessor accessor(&statements);
if (accessor.locate(stmt_id))
{
string* description = accessor.current().description;
const string* description = accessor.current().description;
log = (description != NULL);
// Do not say anything about statements which do not fall under filter criteria
@ -426,7 +426,7 @@ void TracePluginImpl::logRecordStmt(const char* action, TraceConnection* connect
void TracePluginImpl::logRecordServ(const char* action, TraceService* service,
string& line)
{
const ntrace_service_t svc_id = service->getServiceID();
//const ntrace_service_t svc_id = service->getServiceID(); // Unused
bool reg = false;
while (true)
@ -458,7 +458,7 @@ void TracePluginImpl::logRecordServ(const char* action, TraceService* service,
logRecord(action, line);
}
void TracePluginImpl::appendGlobalCounts(PerformanceInfo* info, string& line)
void TracePluginImpl::appendGlobalCounts(const PerformanceInfo* info, string& line)
{
string temp;
@ -494,7 +494,7 @@ void TracePluginImpl::appendGlobalCounts(PerformanceInfo* info, string& line)
line.append(NEWLINE);
}
void TracePluginImpl::appendTableCounts(PerformanceInfo *info, string& line)
void TracePluginImpl::appendTableCounts(const PerformanceInfo *info, string& line)
{
if (!config.print_perf || info->pin_count == 0)
return;
@ -503,8 +503,8 @@ void TracePluginImpl::appendTableCounts(PerformanceInfo *info, string& line)
"Table Natural Index Update Insert Delete Backout Purge Expunge" NEWLINE
"***************************************************************************************************************" NEWLINE );
TraceCounts* trc;
TraceCounts* trc_end;
const TraceCounts* trc;
const TraceCounts* trc_end;
for (trc = info->pin_tables, trc_end = trc + info->pin_count; trc < trc_end; trc++)
{
@ -566,9 +566,15 @@ void TracePluginImpl::formatStringArgument(string& result, const UCHAR* str, siz
{
if (config.max_arg_length && len > config.max_arg_length)
{
/* CVC: We will wrap with the original code.
len = config.max_arg_length - 3;
if (len < 0)
len = 0;
*/
if (config.max_arg_length < 3)
len = 0;
else
len = config.max_arg_length - 3;
result.printf("\"%.*s...\"", len, str);
return;
@ -579,7 +585,7 @@ void TracePluginImpl::formatStringArgument(string& result, const UCHAR* str, siz
void TracePluginImpl::appendParams(TraceParams* params, Firebird::string& line)
{
size_t paramcount = params->getCount();
const size_t paramcount = params->getCount();
if (!paramcount)
return;
@ -781,10 +787,10 @@ void TracePluginImpl::appendServiceQueryParams(size_t send_item_length,
string recv_query;
USHORT l;
SCHAR item;
USHORT timeout = 0;
//USHORT timeout = 0; // Unused
const SCHAR* items = reinterpret_cast<const SCHAR*>(send_items);
const SCHAR* const end_items = items + send_item_length;
const UCHAR* items = send_items;
const UCHAR* const end_items = items + send_item_length;
while (items < end_items && *items != isc_info_end)
{
switch ((item = *items++))
@ -795,7 +801,7 @@ void TracePluginImpl::appendServiceQueryParams(size_t send_item_length,
default:
if (items + 2 <= end_items)
{
l = (USHORT) gds__vax_integer(reinterpret_cast<const UCHAR*>(items), 2);
l = (USHORT) gds__vax_integer(items, 2);
items += 2;
if (items + l <= end_items)
{
@ -809,11 +815,11 @@ void TracePluginImpl::appendServiceQueryParams(size_t send_item_length,
break;
case isc_info_svc_timeout:
send_query.printf(NEWLINE "\t\t set timeout: %d",
(USHORT) gds__vax_integer(reinterpret_cast<const UCHAR*>(items), l));
(USHORT) gds__vax_integer(items, l));
break;
case isc_info_svc_version:
send_query.printf(NEWLINE "\t\t set version: %d",
(USHORT) gds__vax_integer(reinterpret_cast<const UCHAR*>(items), l));
(USHORT) gds__vax_integer(items, l));
break;
}
}
@ -831,8 +837,8 @@ void TracePluginImpl::appendServiceQueryParams(size_t send_item_length,
line.append(send_query);
}
items = reinterpret_cast<const SCHAR*>(recv_items);
const SCHAR* const end_items2 = items + recv_item_length;
items = recv_items;
const UCHAR* const end_items2 = items + recv_item_length;
if (*items == isc_info_length) {
items++;
@ -1036,6 +1042,10 @@ void TracePluginImpl::log_event_attach(TraceConnection* connection,
case res_unauthorized:
event_type = create_db ? "UNAUTHORIZED CREATE_DATABASE" : "UNAUTHORIZED ATTACH_DATABASE";
break;
default:
event_type = create_db ?
"Unknown event in CREATE DATABASE ": "Unknown event in ATTACH_DATABASE";
break;
}
string line;
@ -1127,7 +1137,7 @@ void TracePluginImpl::log_event_transaction_start(TraceConnection* connection,
if (config.log_transactions)
{
string line;
char* event_type;
const char* event_type;
switch (tra_result)
{
case res_successful:
@ -1139,6 +1149,9 @@ void TracePluginImpl::log_event_transaction_start(TraceConnection* connection,
case res_unauthorized:
event_type = "UNAUTHORIZED START_TRANSACTION";
break;
default:
event_type = "Unknown event in START_TRANSACTION";
break;
}
logRecordTrans(event_type, connection, transaction, line);
}
@ -1158,7 +1171,7 @@ void TracePluginImpl::log_event_transaction_end(TraceConnection* connection,
appendTableCounts(info, line);
}
const char* event_type = "<Unknown>";
const char* event_type;
switch (tra_result)
{
case res_successful:
@ -1176,6 +1189,9 @@ void TracePluginImpl::log_event_transaction_end(TraceConnection* connection,
(retain_context ? "UNAUTHORIZED COMMIT_RETAINING" : "UNAUTHORIZED COMMIT_TRANSACTION") :
(retain_context ? "UNAUTHORIZED ROLLBACK_RETAINING" : "UNAUTHORIZED ROLLBACK_TRANSACTION");
break;
default:
event_type = "Unknown event at transaction end";
break;
}
logRecordTrans(event_type, connection, transaction, line);
}
@ -1200,16 +1216,17 @@ void TracePluginImpl::log_event_set_context(
const char* name = variable->getVarName();
const char* value = variable->getVarValue();
size_t ns_len = strlen(ns);
size_t name_len = strlen(name);
size_t value_len = value ? strlen(value) : 0;
const size_t ns_len = strlen(ns);
const size_t name_len = strlen(name);
const size_t value_len = value ? strlen(value) : 0;
if (config.log_context)
{
string line;
if (value == NULL) {
line.printf("[%.*s] %.*s = NULL" NEWLINE, ns_len, ns, name_len, name);
} else {
}
else {
line.printf("[%.*s] %.*s = \"%.*s\"" NEWLINE, ns_len, ns, name_len, name, value_len, value);
}
logRecordTrans("SET_CONTEXT", connection, transaction, line);
@ -1226,7 +1243,7 @@ void TracePluginImpl::log_event_proc_execute(TraceConnection* connection, TraceT
return;
// Do not log operation if it is below time threshold
PerformanceInfo *info = started ? NULL : procedure->getPerf();
const PerformanceInfo *info = started ? NULL : procedure->getPerf();
if (config.time_threshold && info && info->pin_time < config.time_threshold)
return;
@ -1234,7 +1251,7 @@ void TracePluginImpl::log_event_proc_execute(TraceConnection* connection, TraceT
TraceParams *params = procedure->getInputs();
if (params && params->getCount())
{
appendParams(procedure->getInputs(), line);
appendParams(params, line);
line.append(NEWLINE);
}
@ -1250,7 +1267,7 @@ void TracePluginImpl::log_event_proc_execute(TraceConnection* connection, TraceT
appendTableCounts(info, line);
}
const char* event_type = "<Unknown>";
const char* event_type;
switch (proc_result)
{
case res_successful:
@ -1265,6 +1282,9 @@ void TracePluginImpl::log_event_proc_execute(TraceConnection* connection, TraceT
event_type = started ? "UNAUTHORIZED EXECUTE_PROCEDURE_START" :
"UNAUTHORIZED EXECUTE_PROCEDURE_FINISH";
break;
default:
event_type = "Unknown at executing procedure";
break;
}
logRecordProc(event_type, connection, transaction, procedure->getProcName(), line);
@ -1289,7 +1309,7 @@ void TracePluginImpl::register_sql_statement(TraceSQLStatement* statement)
{
if (config.include_filter.hasData())
{
int errorCode = regexec(&include_matcher, sql, 0, NULL, 0);
const int errorCode = regexec(&include_matcher, sql, 0, NULL, 0);
if (errorCode && errorCode != REG_NOMATCH)
{
char errBuf[256];
@ -1303,7 +1323,7 @@ void TracePluginImpl::register_sql_statement(TraceSQLStatement* statement)
if (need_statement && config.exclude_filter.hasData())
{
int errorCode = regexec(&exclude_matcher, sql, 0, NULL, 0);
const int errorCode = regexec(&exclude_matcher, sql, 0, NULL, 0);
if (errorCode && errorCode != REG_NOMATCH)
{
char errBuf[256];
@ -1346,7 +1366,7 @@ void TracePluginImpl::register_sql_statement(TraceSQLStatement* statement)
const char* access_path = config.print_plan ? statement->getPlan() : NULL;
if (access_path && *access_path)
{
size_t access_path_length = strlen(access_path);
const size_t access_path_length = strlen(access_path);
temp.printf(NEWLINE
"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
"%.*s" NEWLINE, access_path_length, access_path);
@ -1377,7 +1397,7 @@ void TracePluginImpl::log_event_dsql_prepare(TraceConnection* connection,
if (config.log_statement_prepare)
{
string line;
char* event_type;
const char* event_type;
switch (req_result)
{
case res_successful:
@ -1389,6 +1409,9 @@ void TracePluginImpl::log_event_dsql_prepare(TraceConnection* connection,
case res_unauthorized:
event_type = "UNAUTHORIZED PREPARE_STATEMENT";
break;
default:
event_type = "Unknown event in PREPARE_STATEMENT";
break;
}
line.printf("%7d ms" NEWLINE, time_millis);
logRecordStmt(event_type, connection, transaction, statement, true, line);
@ -1427,7 +1450,7 @@ void TracePluginImpl::log_event_dsql_execute(TraceConnection* connection,
return;
// Do not log operation if it is below time threshold
PerformanceInfo *info = started ? NULL : statement->getPerf();
const PerformanceInfo *info = started ? NULL : statement->getPerf();
if (config.time_threshold && info && info->pin_time < config.time_threshold)
return;
@ -1450,7 +1473,7 @@ void TracePluginImpl::log_event_dsql_execute(TraceConnection* connection,
appendTableCounts(info, line);
}
const char* event_type = "<Unknown>";
const char* event_type;
switch (req_result)
{
case res_successful:
@ -1465,6 +1488,9 @@ void TracePluginImpl::log_event_dsql_execute(TraceConnection* connection,
event_type = started ? "UNAUTHORIZED EXECUTE_STATEMENT_START" :
"UNAUTHORIZED EXECUTE_STATEMENT_FINISH";
break;
default:
event_type = "Unknown event at executing statement";
break;
}
logRecordStmt(event_type, connection, transaction, statement, true, line);
}
@ -1525,8 +1551,9 @@ void TracePluginImpl::log_event_blr_compile(TraceConnection* connection,
}
string line;
char* event_type;
switch (req_result) {
const char* event_type;
switch (req_result)
{
case res_successful:
event_type = "COMPILE_BLR";
break;
@ -1536,6 +1563,9 @@ void TracePluginImpl::log_event_blr_compile(TraceConnection* connection,
case res_unauthorized:
event_type = "UNAUTHORIZED COMPILE_BLR";
break;
default:
event_type = "Unknown event in COMPILE_BLR";
break;
}
line.printf("%7d ms", time_millis);
@ -1560,7 +1590,7 @@ void TracePluginImpl::log_event_blr_execute(TraceConnection* connection,
appendGlobalCounts(info, line);
appendTableCounts(info, line);
char* event_type;
const char* event_type;
switch (req_result)
{
case res_successful:
@ -1572,6 +1602,9 @@ void TracePluginImpl::log_event_blr_execute(TraceConnection* connection,
case res_unauthorized:
event_type = "UNAUTHORIZED EXECUTE_BLR";
break;
default:
event_type = "Unknown event in EXECUTE_BLR";
break;
}
logRecordStmt(event_type, connection, transaction, statement, false, line);
@ -1613,7 +1646,7 @@ void TracePluginImpl::log_event_dyn_execute(TraceConnection* connection,
}
string line;
char* event_type;
const char* event_type;
switch (req_result)
{
case res_successful:
@ -1625,6 +1658,9 @@ void TracePluginImpl::log_event_dyn_execute(TraceConnection* connection,
case res_unauthorized:
event_type = "UNAUTHORIZED EXECUTE_DYN";
break;
default:
event_type = "Unknown event in EXECUTE_DYN";
break;
}
line.printf("%7d ms", time_millis);
@ -1693,6 +1729,9 @@ void TracePluginImpl::log_event_service_attach(TraceService* service,
case res_unauthorized:
event_type = "UNAUTHORIZED ATTACH_SERVICE";
break;
default:
event_type = "Unknown evnt in ATTACH_SERVICE";
break;
}
string line;
@ -1717,6 +1756,9 @@ void TracePluginImpl::log_event_service_start(TraceService* service,
case res_unauthorized:
event_type = "UNAUTHORIZED START_SERVICE";
break;
default:
event_type = "Unknown event in START_SERVICE";
break;
}
string line;
@ -1774,6 +1816,9 @@ void TracePluginImpl::log_event_service_query(TraceService* service,
case res_unauthorized:
event_type = "UNAUTHORIZED QUERY_SERVICE";
break;
default:
event_type = "Unknown event in QUERY_SERVICE";
break;
}
logRecordServ(event_type, service, line);
@ -1796,6 +1841,9 @@ void TracePluginImpl::log_event_service_detach(TraceService* service, ntrace_res
case res_unauthorized:
event_type = "UNAUTHORIZED DETACH_SERVICE";
break;
default:
event_type = "Unknown event in DETACH_SERVICE";
break;
}
string line;
logRecordServ(event_type, service, line);
@ -1822,7 +1870,7 @@ void TracePluginImpl::log_event_trigger_execute(TraceConnection* connection, Tra
return;
// Do not log operation if it is below time threshold
PerformanceInfo *info = started ? NULL : trigger->getPerf();
const PerformanceInfo *info = started ? NULL : trigger->getPerf();
if (config.time_threshold && info && info->pin_time < config.time_threshold)
return;
@ -1882,6 +1930,9 @@ void TracePluginImpl::log_event_trigger_execute(TraceConnection* connection, Tra
case jrd_req::req_trigger_trans_rollback:
action.append("TRANSACTION_ROLLBACK");
break;
default:
action.append("Unknown trigger action");
break;
}
line.printf("\t%s (%s) " NEWLINE, trgname.c_str(), action.c_str());
@ -1907,6 +1958,9 @@ void TracePluginImpl::log_event_trigger_execute(TraceConnection* connection, Tra
event_type = started ? "UNAUTHORIZED EXECUTE_TRIGGER_START" :
"UNAUTHORIZED EXECUTE_TRIGGER_FINISH";
break;
default:
event_type = "Unknown event at executing trigger";
break;
}
logRecordTrans(event_type, connection, transaction, line);

View File

@ -140,7 +140,7 @@ private:
bool operational; // Set if plugin is fully initialized and is ready for logging
// Keep this member field first to ensure its correctness
// when destructor is called
int session_id; // trace session ID, set by Firebird
const int session_id; // trace session ID, set by Firebird
Firebird::string session_name; // trace session name, set by Firebird
FileObject* logFile; // Thread-safe
TraceLogWriter* logWriter;
@ -169,8 +169,8 @@ private:
void rotateLog(size_t added_bytes_length);
void writePacket(const UCHAR* packet_data, const ULONG packet_size);
void appendGlobalCounts(PerformanceInfo* info, Firebird::string& line);
void appendTableCounts(PerformanceInfo* info, Firebird::string& line);
void appendGlobalCounts(const PerformanceInfo* info, Firebird::string& line);
void appendTableCounts(const PerformanceInfo* info, Firebird::string& line);
void appendParams(TraceParams* params, Firebird::string& line);
void appendServiceQueryParams(size_t send_item_length,
const ntrace_byte_t* send_items, size_t recv_item_length,

View File

@ -26,7 +26,7 @@
#log_filename
# Maximum size of log file (megabytes). Used by system audit trace for
# log's rotation : when current log file reached this limit its renamed
# log's rotation : when current log file reached this limit it is renamed
# using current date and time and new log file is created
max_log_size 0

View File

@ -25,8 +25,8 @@
*
*/
#ifndef FILEOBJECT_H
#define FILEOBJECT_H
#ifndef OS_FILEOBJECT_H
#define OS_FILEOBJECT_H
#include "../../../common/classes/fb_string.h"
#include "../../../common/classes/locks.h"
@ -180,4 +180,4 @@ private:
#endif
};
#endif // FILEOBJECT_H
#endif // OS_FILEOBJECT_H

View File

@ -25,8 +25,8 @@
*
*/
#ifndef PLATFORM_H
#define PLATFORM_H
#ifndef OS_PLATFORM_H
#define OS_PLATFORM_H
const char* get_error_string();
@ -34,4 +34,4 @@ void set_error_string(const char* str);
SLONG get_process_id();
#endif // PLATFORM_H
#endif // OS_PLATFORM_H

View File

@ -147,7 +147,7 @@ bool FileObject::renameFile(const Firebird::PathName new_filename)
{
int rename_err = errno;
if (rename_err == ENOENT || rename_err == EEXIST) {
// Another process renames our file just now. Open new it.
// Another process renames our file just now. Open it again.
reopen();
return false;
}

View File

@ -31,8 +31,10 @@
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#define TEST
//#undef TEST
#ifndef TEST
class MallocClear
{
@ -60,17 +62,18 @@ void set_error_string(const char* str)
}
if (str)
{
size_t len = strlen(str);
char* new_str = (char*) malloc(len + 1);
const size_t size = strlen(str) + 1;
char* new_str = (char*) malloc(size);
if (new_str)
{
memcpy(new_str, str, len + 1);
memcpy(new_str, str, size);
error_value.set(new_str);
}
}
}
#else
TLS_DECLARE(char*, error_string);
const char* get_error_string()
{
return TLS_GET(error_string);
@ -86,16 +89,17 @@ void set_error_string(const char* str)
}
if (str)
{
size_t len = strlen(str);
char* new_str = (char*) malloc(len + 1);
const size_t size = strlen(str) + 1;
char* new_str = (char*) malloc(size);
if (new_str)
{
memcpy(new_str, str, len + 1);
memcpy(new_str, str, size);
TLS_SET(error_string, new_str);
}
}
}
#endif
SLONG get_process_id()
{
return getpid();

View File

@ -239,7 +239,7 @@ bool FileObject::renameFile(const Firebird::PathName new_filename)
DWORD rename_err = GetLastError();
if (rename_err == ERROR_ALREADY_EXISTS || rename_err == ERROR_FILE_NOT_FOUND)
{
// Another process renames our file just now. Open new it.
// Another process renames our file just now. Open it again.
reopen();
return false;
}
@ -261,7 +261,6 @@ SINT64 FileObject::seek(SINT64 newOffset, SeekOrigin origin)
{
LARGE_INTEGER offset;
offset.QuadPart = newOffset;
DWORD error;
DWORD moveMethod;
switch(origin)
@ -277,6 +276,7 @@ SINT64 FileObject::seek(SINT64 newOffset, SeekOrigin origin)
break;
}
DWORD error;
if ((offset.LowPart = SetFilePointer(file, offset.LowPart,
&offset.HighPart, moveMethod)) == INVALID_SET_FILE_POINTER &&
(error = GetLastError()) != NO_ERROR)

View File

@ -48,11 +48,11 @@ void set_error_string(const char* str)
if (str)
{
size_t len = strlen(str);
char* new_str = (char*) LocalAlloc(LMEM_FIXED, len + 1);
const size_t size = strlen(str) + 1;
char* new_str = (char*) LocalAlloc(LMEM_FIXED, size);
if (new_str)
{
memcpy(new_str, str, len + 1);
memcpy(new_str, str, size);
TLS_SET(error_string, new_str);
}
}