summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2013-10-20 23:09:46 +0200
committerUwe Hermann <uwe@hermann-uwe.de>2013-10-20 23:34:32 +0200
commit74bb0af5daeef0d9abcf382b238e84376b1e006b (patch)
treea3b6722cc13207743c8454561746e3263272eaea
parent269b442df38c1cfe825fd397612f8f79aea5541d (diff)
downloadlibsigrokdecode-74bb0af5daeef0d9abcf382b238e84376b1e006b.tar.gz
libsigrokdecode-74bb0af5daeef0d9abcf382b238e84376b1e006b.zip
session: Add some more parameter checks, minor other fixes.
Some of these also fix unit tests that were previously failing.
-rw-r--r--controller.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/controller.c b/controller.c
index 4d8357d..635e47e 100644
--- a/controller.c
+++ b/controller.c
@@ -809,8 +809,9 @@ SRD_PRIV int srd_inst_decode(uint64_t start_samplenum,
srd_logic *logic;
uint64_t end_samplenum;
- srd_dbg("Calling decode() on instance %s with %d bytes starting "
- "at sample %d.", di->inst_id, inbuflen, start_samplenum);
+ srd_dbg("Calling decode() on instance %s with %" PRIu64 " bytes "
+ "starting at sample %" PRIu64 ".", di->inst_id, inbuflen,
+ start_samplenum);
/* Return an error upon unusable input. */
if (!di) {
@@ -936,7 +937,7 @@ SRD_API int srd_session_new(struct srd_session **sess)
if (!sess) {
srd_err("Invalid session pointer.");
- return SRD_ERR;
+ return SRD_ERR_ARG;
}
if (!(*sess = g_try_malloc(sizeof(struct srd_session))))
@@ -992,7 +993,8 @@ SRD_API int srd_session_start(struct srd_session *sess)
ret = SRD_OK;
srd_dbg("Calling start() on all instances in session %d with "
- "%d probes, unitsize %d, samplerate %d.", sess->session_id,
+ "%" PRIu64 " probes, unitsize %" PRIu64
+ ", samplerate %" PRIu64 ".", sess->session_id,
sess->num_probes, sess->unitsize, sess->samplerate);
/*
@@ -1041,8 +1043,13 @@ SRD_API int srd_session_config_set(struct srd_session *sess, int key,
return SRD_ERR_ARG;
}
+ if (!data) {
+ srd_err("Invalid config data.");
+ return SRD_ERR_ARG;
+ }
+
if (!g_variant_is_of_type(data, G_VARIANT_TYPE_UINT64)) {
- srd_err("Value for key %d should be of type uint64.");
+ srd_err("Value for key %d should be of type uint64.", key);
return SRD_ERR_ARG;
}
@@ -1056,6 +1063,9 @@ SRD_API int srd_session_config_set(struct srd_session *sess, int key,
case SRD_CONF_SAMPLERATE:
sess->samplerate = g_variant_get_uint64(data);
break;
+ default:
+ srd_err("Cannot set config for unknown key %d.", key);
+ return SRD_ERR_ARG;
}
g_variant_unref(data);
@@ -1114,6 +1124,11 @@ SRD_API int srd_session_destroy(struct srd_session *sess)
{
int session_id;
+ if (!sess) {
+ srd_err("Invalid session.");
+ return SRD_ERR_ARG;
+ }
+
session_id = sess->session_id;
if (sess->di_list)
srd_inst_free_all(sess, NULL);