Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[svace] Fix errors, found by svace static analyzer #207

Open
wants to merge 2 commits into
base: 3.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions libmariadb/ma_dtoa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1684,8 +1684,9 @@ static char *dtoa(double dd, int mode, int ndigits, int *decpt, int *sign,
Bfree(b, &alloc);
b= b1;
}
if ((j= b5 - m5))
b= pow5mult(b, j, &alloc);
// redundant comparison, as m5 == b5
//if ((j= b5 - m5))
// b= pow5mult(b, j, &alloc);
}
else
b= pow5mult(b, b5, &alloc);
Expand Down
2 changes: 1 addition & 1 deletion libmariadb/ma_hashtbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ my_bool ma_hashtbl_insert(MA_HASHTBL *info,const uchar *record)
gpos->data=ptr_to_rec;
gpos->next=NO_RECORD;
}
if ((flag & (HIGHFIND | HIGHUSED)) == HIGHFIND)
if (gpos2 && (flag & (HIGHFIND | HIGHUSED)) == HIGHFIND)
{
gpos2->data=ptr_to_rec2;
gpos2->next=NO_RECORD;
Expand Down
6 changes: 3 additions & 3 deletions libmariadb/ma_stmt_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ void ps_fetch_datetime(MYSQL_BIND *r_param, const MYSQL_FIELD * field,
}
default:
{
char dtbuffer[60];
char dtbuffer[87];
MYSQL_TIME tm;
size_t length;
convert_to_datetime(&tm, row, len, field->type);
Expand All @@ -1148,7 +1148,7 @@ void ps_fetch_datetime(MYSQL_BIND *r_param, const MYSQL_FIELD * field,
length= sprintf(dtbuffer, "%s%02u:%02u:%02u", (tm.neg ? "-" : ""), tm.hour, tm.minute, tm.second);
if (field->decimals && field->decimals <= 6)
{
char ms[8];
char ms[22];
sprintf(ms, ".%06lu", tm.second_part);
if (field->decimals < 6)
ms[field->decimals + 1]= 0;
Expand All @@ -1161,7 +1161,7 @@ void ps_fetch_datetime(MYSQL_BIND *r_param, const MYSQL_FIELD * field,
length= sprintf(dtbuffer, "%04u-%02u-%02u %02u:%02u:%02u", tm.year, tm.month, tm.day, tm.hour, tm.minute, tm.second);
if (field->decimals && field->decimals <= 6)
{
char ms[8];
char ms[22];
sprintf(ms, ".%06lu", tm.second_part);
if (field->decimals < 6)
ms[field->decimals + 1]= 0;
Expand Down
3 changes: 2 additions & 1 deletion libmariadb/mariadb_dyncol.c
Original file line number Diff line number Diff line change
Expand Up @@ -3830,7 +3830,8 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val,
return ER_DYNCOL_RESOURCE;
if (quote)
str->str[str->length++]= quote;
ma_dynstr_append_mem(str, buff, len);
if (ma_dynstr_append_mem(str, buff, len))
return ER_DYNCOL_RESOURCE;
if (quote)
str->str[str->length++]= quote;
break;
Expand Down
13 changes: 10 additions & 3 deletions libmariadb/mariadb_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ ulong
net_field_length(uchar **packet)
{
reg1 uchar *pos= *packet;
if (!pos)
return NULL_LENGTH;

if (*pos < 251)
{
(*packet)++;
Expand Down Expand Up @@ -1043,7 +1046,7 @@ unpack_fields(const MYSQL *mysql,
for (i=0; i < field_count; i++)
{
uint length= (uint)(row->data[i+1] - row->data[i] - 1);
if (!row->data[i] && row->data[i][length])
if (!row->data[i] || row->data[i][length])
goto error;

*(char **)(((char *)field) + rset_field_offsets[i*2])=
Expand Down Expand Up @@ -1246,8 +1249,12 @@ int mthd_my_read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths)
*prev_pos=0; /* Terminate prev field */
prev_pos=pos;
}
row[field]=(char*) prev_pos+1; /* End of last field */
*prev_pos=0; /* Terminate last field */

if (prev_pos)
{
row[field]=(char*) prev_pos+1; /* End of last field */
*prev_pos=0; /* Terminate last field */
}
return 0;
}

Expand Down
3 changes: 2 additions & 1 deletion libmariadb/mariadb_rpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,8 @@ int mariadb_rpl_optionsv(MARIADB_RPL *rpl,
else if (arg1)
{
rpl->filename= strdup((const char *)arg1);
rpl->filename_length= (uint32_t)strlen(rpl->filename);
if (rpl->filename)
rpl->filename_length= (uint32_t)strlen(rpl->filename);
}
break;
}
Expand Down
6 changes: 4 additions & 2 deletions libmariadb/mariadb_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ int mthd_stmt_fetch_to_bind(MYSQL_STMT *stmt, unsigned char *row)
if (!stmt->bind[i].is_null)
stmt->bind[i].is_null= &stmt->bind[i].is_null_value;
*stmt->bind[i].is_null= 0;
mysql_ps_fetch_functions[stmt->fields[i].type].func(&stmt->bind[i], &stmt->fields[i], &row);
if (mysql_ps_fetch_functions[stmt->fields[i].type].func != NULL)
mysql_ps_fetch_functions[stmt->fields[i].type].func(&stmt->bind[i], &stmt->fields[i], &row);
if (stmt->mysql->options.report_data_truncation)
truncations+= *stmt->bind[i].error;
}
Expand Down Expand Up @@ -1560,7 +1561,8 @@ int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind, unsigned
*bind[0].error= 0;
bind[0].offset= offset;
save_ptr= stmt->bind[column].u.row_ptr;
mysql_ps_fetch_functions[stmt->fields[column].type].func(&bind[0], &stmt->fields[column], &stmt->bind[column].u.row_ptr);
if (mysql_ps_fetch_functions[stmt->fields[column].type].func != NULL)
mysql_ps_fetch_functions[stmt->fields[column].type].func(&bind[0], &stmt->fields[column], &stmt->bind[column].u.row_ptr);
stmt->bind[column].u.row_ptr= save_ptr;
}
return(0);
Expand Down