Skip to content

Commit 1a0aa14

Browse files
committed
Replace asserts with SystemErrors
1 parent 28b0c06 commit 1a0aa14

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/cstring.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ static PyObject *cstring_richcompare(PyObject *self, PyObject *other, int op) {
8686
case Py_GE:
8787
return PyBool_FromLong(*left >= *right);
8888
default:
89-
assert(0);
89+
/* Should be unreachable */
90+
PyErr_Format(PyExc_SystemError, "Invalid compare operation: %d", op);
91+
return NULL;
9092
}
9193
}
9294

@@ -158,7 +160,10 @@ static PyObject *_cstring_subscript_slice(PyObject *self, PyObject *slice) {
158160
if(PySlice_Unpack(slice, &start, &stop, &step) < 0)
159161
return NULL;
160162
Py_ssize_t slicelen = PySlice_AdjustIndices(cstring_len(self), &start, &stop, step);
161-
assert(slicelen >= 0);
163+
if(slicelen < 0) {
164+
PyErr_Format(PyExc_SystemError, "Internal error: Invalid slicelen: %d", slicelen);
165+
return NULL;
166+
}
162167

163168
struct cstring *new = (struct cstring *)Py_TYPE(self)->tp_alloc(Py_TYPE(self), slicelen + 1);
164169
char *src = CSTRING_VALUE_AT(self, start);

0 commit comments

Comments
 (0)