fix: null tag caused crash

This commit is contained in:
Tobias Reisinger 2020-01-02 21:55:42 +01:00
parent 7867c9405c
commit 3afb857208
2 changed files with 16 additions and 3 deletions

View file

@ -43,6 +43,7 @@ static controller_dbo*
controller_db_select_mapper(sqlite3_stmt *stmt)
{
auto *new_controller = new controller_dbo();
const char* new_tag;
for(int i = 0; i < sqlite3_column_count(stmt); i++)
{
const char *name = sqlite3_column_name(stmt, i);
@ -74,7 +75,12 @@ controller_db_select_mapper(sqlite3_stmt *stmt)
new_controller->relay_count = sqlite3_column_int(stmt, i);
break;
case 't': // tag
new_tag = (const char*)sqlite3_column_text(stmt, i);
new_controller->tag[0] = '\0';
if(new_tag)
{
strncpy(new_controller->tag, (const char*)sqlite3_column_text(stmt, i), 63);
}
break;
default: // ignore columns not implemented
break;

View file

@ -34,6 +34,7 @@ static relay_dbo*
relay_db_select_mapper(sqlite3_stmt *stmt)
{
auto *new_relay = new relay_dbo();
const char* new_tag;
for(int i = 0; i < sqlite3_column_count(stmt); i++)
{
const char *name = sqlite3_column_name(stmt, i);
@ -60,8 +61,14 @@ relay_db_select_mapper(sqlite3_stmt *stmt)
default:
break;
}
break;
case 't': // tag
new_tag = (const char*)sqlite3_column_text(stmt, i);
new_relay->tag[0] = '\0';
if(new_tag)
{
strncpy(new_relay->tag, (const char*)sqlite3_column_text(stmt, i), 63);
}
break;
default: // ignore columns not implemented
break;