fix: null tag caused crash
This commit is contained in:
		
							parent
							
								
									7867c9405c
								
							
						
					
					
						commit
						3afb857208
					
				
					 2 changed files with 16 additions and 3 deletions
				
			
		| 
						 | 
					@ -43,6 +43,7 @@ static controller_dbo*
 | 
				
			||||||
controller_db_select_mapper(sqlite3_stmt *stmt)
 | 
					controller_db_select_mapper(sqlite3_stmt *stmt)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    auto *new_controller = new controller_dbo();
 | 
					    auto *new_controller = new controller_dbo();
 | 
				
			||||||
 | 
					    const char* new_tag;
 | 
				
			||||||
    for(int i = 0; i < sqlite3_column_count(stmt); i++)
 | 
					    for(int i = 0; i < sqlite3_column_count(stmt); i++)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        const char *name = sqlite3_column_name(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);
 | 
					                new_controller->relay_count = sqlite3_column_int(stmt, i);
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case 't': // tag
 | 
					            case 't': // tag
 | 
				
			||||||
                strncpy(new_controller->tag, (const char*)sqlite3_column_text(stmt, i), 63);
 | 
					                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;
 | 
					                break;
 | 
				
			||||||
            default: // ignore columns not implemented
 | 
					            default: // ignore columns not implemented
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,6 +34,7 @@ static relay_dbo*
 | 
				
			||||||
relay_db_select_mapper(sqlite3_stmt *stmt)
 | 
					relay_db_select_mapper(sqlite3_stmt *stmt)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    auto *new_relay = new relay_dbo();
 | 
					    auto *new_relay = new relay_dbo();
 | 
				
			||||||
 | 
					    const char* new_tag;
 | 
				
			||||||
    for(int i = 0; i < sqlite3_column_count(stmt); i++)
 | 
					    for(int i = 0; i < sqlite3_column_count(stmt); i++)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        const char *name = sqlite3_column_name(stmt, i);
 | 
					        const char *name = sqlite3_column_name(stmt, i);
 | 
				
			||||||
| 
						 | 
					@ -60,8 +61,14 @@ relay_db_select_mapper(sqlite3_stmt *stmt)
 | 
				
			||||||
                    default:
 | 
					                    default:
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
            case 't': // tag
 | 
					            case 't': // tag
 | 
				
			||||||
                strncpy(new_relay->tag, (const char*)sqlite3_column_text(stmt, i), 63);
 | 
					                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;
 | 
					                break;
 | 
				
			||||||
            default: // ignore columns not implemented
 | 
					            default: // ignore columns not implemented
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue