Skip to content

Commit

Permalink
coverity scan fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
9EOR9 committed Jun 24, 2020
1 parent 1a1b033 commit fa61a66
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/mariadb_codecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,7 @@ mariadb_get_parameter(MrdbCursor *self,
/* check if row_nr and column_nr are in the range from
0 to (value - 1) */
if (row_nr > (self->array_size - 1) ||
column_nr > (self->param_count - 1) ||
row_nr < 0 ||
column_nr < 0)
column_nr > (self->param_count - 1))
{
mariadb_throw_exception(self->stmt, Mariadb_DataError, 0,
"Can't access data at row %d, column %d",
Expand Down
1 change: 1 addition & 0 deletions src/mariadb_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,7 @@ PyObject *MrdbConnection_reconnect(MrdbConnection *self)
MARIADB_CHECK_CONNECTION(self, NULL);

mysql_get_option(self->mysql, MYSQL_OPT_RECONNECT, &save_reconnect);
/* coverity[copy_paste_error] */
if (!save_reconnect)
mysql_optionsv(self->mysql, MYSQL_OPT_RECONNECT, &reconnect);

Expand Down
5 changes: 3 additions & 2 deletions src/mariadb_cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1034,13 +1034,14 @@ MrdbCursor_scroll(MrdbCursor *self,

if (!mode)
{
new_position= self->row_number + position;
if (new_position < 0 || new_position > CURSOR_NUM_ROWS(self))
if ((long long)self->row_number + position < 0 ||
self->row_number + position > CURSOR_NUM_ROWS(self))
{
mariadb_throw_exception(NULL, Mariadb_DataError, 0,
"Position value is out of range");
return NULL;
}
new_position= self->row_number + position;
}
else {
new_position= position; /* absolute */
Expand Down
18 changes: 13 additions & 5 deletions src/mariadb_field.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ Mariadb_Fieldinfo_getflag(Mariadb_Fieldinfo *self, PyObject *args)
PyObject *data= NULL;
PyObject *flag= NULL;
char str_flag[512]= {0};
char *p, *end;

if (!PyArg_ParseTuple(args, "O!", &PyTuple_Type, &data))
{
Expand Down Expand Up @@ -267,21 +268,28 @@ Mariadb_Fieldinfo_getflag(Mariadb_Fieldinfo *self, PyObject *args)
goto end;
}

p= &str_flag[0];
end= p + 511;

while(flag_name[i].name)
{
if (flag_val & flag_name[i].flag)
{
if (!str_flag[0])
if (str_flag[0] &&
end - p > 3)
{
strcat(str_flag, flag_name[i].name);
strcpy(p, " | ");
p+= 3;
}
else {
strcat(str_flag, " | ");
strcat(str_flag, flag_name[i].name);
if ((ssize_t)strlen(flag_name[i].name) < end - p)
{
strcpy(p, flag_name[i].name);
p+= strlen(flag_name[i].name);
}
}
i++;
}
*p= 0;
end:
return PyUnicode_FromString(str_flag);
}

0 comments on commit fa61a66

Please sign in to comment.