Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Commit

Permalink
fix floating truncation; reduce debug spew
Browse files Browse the repository at this point in the history
  • Loading branch information
mtijanic committed Apr 2, 2018
1 parent 103401b commit b0d3f87
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
Binary file modified lib/detours/lib/detours.lib
Binary file not shown.
13 changes: 7 additions & 6 deletions mysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void sql_destroy_prepared_query() {
int sql_prepare_query(const char *query) {
LOG_INFO("SQL prepare query: %s", query);
if (sql.stmt) {
LOG_INFO("Destroying previous query");
LOG_DEBUG("Destroying previous query");
sql_destroy_prepared_query();
}

Expand All @@ -64,7 +64,7 @@ int sql_prepare_query(const char *query) {

if (!mysql_stmt_prepare(sql.stmt, query, strlen(query))) {
sql.paramCount = mysql_stmt_param_count(sql.stmt);
LOG_INFO("Detected %d parameters.", sql.paramCount);
LOG_DEBUG("Detected %d parameters.", sql.paramCount);
assert(sql.paramCount < count_of(sql.params));
return 1;
}
Expand All @@ -86,7 +86,7 @@ int sql_execute_prepared_query() {
}

if (!mysql_stmt_execute(sql.stmt)) {
LOG_INFO("Successful query");
LOG_DEBUG("Successful query");
sql.result = mysql_stmt_result_metadata(sql.stmt);
if (sql.result) {
sql.columns = mysql_num_fields(sql.result);
Expand Down Expand Up @@ -122,15 +122,16 @@ int sql_read_next_row() {
}

for (int i = 0; i < sql.columns; i++) {
sql.lengths[i] += 128;
sql.resultBuffer[i] = realloc(sql.resultBuffer[i], sql.lengths[i] + 1);
//assert(sql.resultBuffer[i]);
LOG_INFO("Column %d of %d, length %d; res: %p", i, sql.columns, sql.lengths[i], sql.resultBuffer[i]);
LOG_DEBUG("Column %d of %d, length %d; res: %p", i, sql.columns, sql.lengths[i], sql.resultBuffer[i]);

sql.binds[i].buffer = sql.resultBuffer[i];
sql.binds[i].buffer_length = sql.lengths[i];
int fetched = mysql_stmt_fetch_column(sql.stmt, &sql.binds[i], i, 0);
sql.resultBuffer[i][sql.lengths[i]] = 0;
LOG_INFO("fetched = %d", fetched);
LOG_DEBUG("fetched = %d", fetched);
}
sql.currentRow++;
return 1;
Expand All @@ -140,7 +141,7 @@ char *sql_read_data_in_active_row(int column) {
if (!sql.stmt || column < 0 || column >= sql.columns)
return "";

LOG_INFO("Reading column %d, value %s", column, sql.resultBuffer[column]);
LOG_DEBUG("Reading column %d, value %s", column, sql.resultBuffer[column]);
return sql.resultBuffer[column];
}
int sql_get_affected_rows() {
Expand Down
10 changes: 10 additions & 0 deletions nwnxlite.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ __declspec(dllexport) void dummy() { }
FILE *logfile;
struct cfg cfg;

int loglevel = 1;

void parse_config() {
FILE *f = fopen("nwnxlite.ini", "r");
if (!f) {
Expand Down Expand Up @@ -37,6 +39,14 @@ void (__fastcall *CNWSScriptVarTable__SetString)(CNWSScriptVarTable* thisP
void SQLExecDirect(char *name, char *value);
char *SQLFetch(char *name);
char *SQLGetData(char *name);
void SetLogLevel(char *name, char *value) {
switch (*value) {
case '1': loglevel = 1; break;
case '2': loglevel = 2; break;
case '0': loglevel - 0; break;
}
}

struct {
const char *cmd;
SetStringHandler handler;
Expand Down
5 changes: 3 additions & 2 deletions nwnxlite.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#include "string.h"

extern FILE *logfile;
extern int loglevel;
#define LOG_INIT(logname) (logfile = fopen(logname, "w"))
#define LOG_DEBUG(fmt, ...) (fprintf(logfile, "[DEBUG] " fmt "\n", ##__VA_ARGS__), fflush(logfile))
#define LOG_INFO(fmt, ...) (fprintf(logfile, "[INFO] " fmt "\n", ##__VA_ARGS__), fflush(logfile))
#define LOG_DEBUG(fmt, ...) if (loglevel >= 2) { fprintf(logfile, "[DEBUG] " fmt "\n", ##__VA_ARGS__), fflush(logfile); } else
#define LOG_INFO(fmt, ...) if (loglevel >= 1) { fprintf(logfile, "[INFO] " fmt "\n", ##__VA_ARGS__), fflush(logfile); } else
#define LOG_ERROR(fmt, ...) (fprintf(logfile, "[ERROR] " fmt "\n", ##__VA_ARGS__), fflush(logfile))
#define LOG_CLOSE() (fclose(logfile))

Expand Down

0 comments on commit b0d3f87

Please sign in to comment.