Skip to content

Commit 70bacef

Browse files
authored
Change end to a char and catch missing parsing cases
1 parent 71c173c commit 70bacef

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

singlestoredb/mysql/accel.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ static PyObject *read_row_from_packet(
12131213
PyObject *py_result = NULL;
12141214
PyObject *py_item = NULL;
12151215
PyObject *py_str = NULL;
1216-
char *end = NULL;
1216+
char end = '\0';
12171217

12181218
int sign = 1;
12191219
int year = 0;
@@ -1240,7 +1240,7 @@ static PyObject *read_row_from_packet(
12401240
for (unsigned long i = 0; i < py_state->n_cols; i++) {
12411241

12421242
read_length_coded_string(&data, &data_l, &out, &out_l, &is_null);
1243-
end = &out[out_l];
1243+
end = out[out_l];
12441244

12451245
orig_out = out;
12461246
orig_out_l = out_l;
@@ -1267,10 +1267,6 @@ static PyObject *read_row_from_packet(
12671267

12681268
// If no converter was passed in, do the default processing.
12691269
else {
1270-
// Make sure not to overrun
1271-
char tmp = *end;
1272-
if (data_l) *end = '\0';
1273-
12741270
switch (py_state->type_codes[i]) {
12751271
case MYSQL_TYPE_NEWDECIMAL:
12761272
case MYSQL_TYPE_DECIMAL:
@@ -1287,16 +1283,21 @@ static PyObject *read_row_from_packet(
12871283
case MYSQL_TYPE_LONG:
12881284
case MYSQL_TYPE_LONGLONG:
12891285
case MYSQL_TYPE_INT24:
1286+
if (data_l) out[out_l] = '\0';
12901287
if (py_state->flags[i] & MYSQL_FLAG_UNSIGNED) {
12911288
py_item = PyLong_FromUnsignedLongLong(strtoull(out, NULL, 10));
12921289
} else {
12931290
py_item = PyLong_FromLongLong(strtoll(out, NULL, 10));
12941291
}
1292+
if (data_l) out[out_l] = end;
12951293
if (!py_item) goto error;
12961294
break;
1295+
12971296
case MYSQL_TYPE_FLOAT:
12981297
case MYSQL_TYPE_DOUBLE:
1299-
py_item = PyFloat_FromDouble(strtod(out, &end));
1298+
if (data_l) out[out_l] = '\0';
1299+
py_item = PyFloat_FromDouble(strtod(out, NULL));
1300+
if (data_l) out[out_l] = end;
13001301
if (!py_item) goto error;
13011302
break;
13021303

@@ -1428,8 +1429,10 @@ static PyObject *read_row_from_packet(
14281429
goto error;
14291430
break;
14301431
}
1432+
if (data_l) out[out_l] = '\0';
14311433
year = strtoul(out, NULL, 10);
14321434
py_item = PyLong_FromLong(year);
1435+
if (data_l) out[out_l] = end;
14331436
if (!py_item) goto error;
14341437
break;
14351438

@@ -1469,7 +1472,6 @@ static PyObject *read_row_from_packet(
14691472
py_state->type_codes[i], NULL);
14701473
goto error;
14711474
}
1472-
if (data_l) *end = tmp;
14731475
}
14741476
}
14751477

0 commit comments

Comments
 (0)