X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=type_decoder.c;h=2f15ee6115571a723853e0a8a2685cc3346c8a11;hp=35187a598a2d6ca19c5f09441f02955340e2468b;hb=7969d8035530d40753c4f880c90a4e90f9679ccc;hpb=8ad9a3e48ddf79e08cd48073c953ea665c464005 diff --git a/type_decoder.c b/type_decoder.c index 35187a5..2f15ee6 100644 --- a/type_decoder.c +++ b/type_decoder.c @@ -26,8 +26,7 @@ typedef struct { PyObject_HEAD } srd_Decoder; -/* This is only used for nicer srd_dbg() output. - */ +/* This is only used for nicer srd_dbg() output. */ static const char *output_type_name(unsigned int idx) { static const char names[][16] = { @@ -37,6 +36,7 @@ static const char *output_type_name(unsigned int idx) "OUTPUT_META", "(invalid)" }; + return names[MIN(idx, G_N_ELEMENTS(names) - 1)]; } @@ -125,8 +125,7 @@ static void release_binary(struct srd_proto_data_binary *pdb) { if (!pdb) return; - if (pdb->data) - g_free((void *)pdb->data); + g_free((void *)pdb->data); g_free(pdb); } @@ -333,8 +332,10 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args) Py_XDECREF(py_res); } if ((cb = srd_pd_output_callback_find(di->sess, pdo->output_type))) { - /* Frontends aren't really supposed to get Python - * callbacks, but it's useful for testing. */ + /* + * Frontends aren't really supposed to get Python + * callbacks, but it's useful for testing. + */ pdata.data = py_data; cb->cb(&pdata, cb->cb_data); } @@ -391,7 +392,7 @@ static PyObject *Decoder_register(PyObject *self, PyObject *args, const GVariantType *meta_type_gv; int output_type; char *proto_id, *meta_name, *meta_descr; - char *keywords[] = {"output_type", "proto_id", "meta", NULL}; + char *keywords[] = { "output_type", "proto_id", "meta", NULL }; PyGILState_STATE gstate; gboolean is_meta; GSList *l; @@ -408,7 +409,7 @@ static PyObject *Decoder_register(PyObject *self, PyObject *args, goto err; } - /* Default to instance id, which defaults to class id. */ + /* Default to instance ID, which defaults to class ID. */ proto_id = di->inst_id; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|s(Oss)", keywords, &output_type, &proto_id, @@ -497,6 +498,8 @@ static int get_term_type(const char *v) return SRD_TERM_EITHER_EDGE; case 'n': return SRD_TERM_NO_EDGE; + default: + return -1; } return -1; @@ -836,7 +839,9 @@ static PyObject *Decoder_wait(PyObject *self, PyObject *args) * while the termination request still gets signalled. */ found_match = FALSE; - ret = process_samples_until_condition_match(di, &found_match); + + /* Ignore return value for now, should never be negative. */ + (void)process_samples_until_condition_match(di, &found_match); Py_END_ALLOW_THREADS @@ -954,14 +959,14 @@ err: } static PyMethodDef Decoder_methods[] = { - {"put", Decoder_put, METH_VARARGS, - "Accepts a dictionary with the following keys: startsample, endsample, data"}, - {"register", (PyCFunction)Decoder_register, METH_VARARGS|METH_KEYWORDS, - "Register a new output stream"}, - {"wait", Decoder_wait, METH_VARARGS, - "Wait for one or more conditions to occur"}, - {"has_channel", Decoder_has_channel, METH_VARARGS, - "Report whether a channel was supplied"}, + { "put", Decoder_put, METH_VARARGS, + "Accepts a dictionary with the following keys: startsample, endsample, data" }, + { "register", (PyCFunction)Decoder_register, METH_VARARGS|METH_KEYWORDS, + "Register a new output stream" }, + { "wait", Decoder_wait, METH_VARARGS, + "Wait for one or more conditions to occur" }, + { "has_channel", Decoder_has_channel, METH_VARARGS, + "Report whether a channel was supplied" }, {NULL, NULL, 0, NULL} };