From: Bert Vermeulen Date: Sun, 17 Nov 2013 23:03:53 +0000 (+0100) Subject: Better error checking on session metadata X-Git-Tag: libsigrokdecode-0.3.0~226 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ca27aa8f9d91d68bfd55fb17fea181a1ba6054a4;p=libsigrokdecode.git Better error checking on session metadata --- diff --git a/session.c b/session.c index 109ede1..7eeab16 100644 --- a/session.c +++ b/session.c @@ -170,10 +170,27 @@ SRD_API int srd_session_metadata_set(struct srd_session *sess, int key, return SRD_ERR_ARG; } + if (!key) { + srd_err("Invalid key."); + return SRD_ERR_ARG; + } + + if (!data) { + srd_err("Invalid value."); + return SRD_ERR_ARG; + } + + /* Hardcoded to samplerate/uint64 for now. */ + if (key != SRD_CONF_SAMPLERATE) { srd_err("Unknown config key %d.", key); return SRD_ERR_ARG; } + if (!g_variant_is_of_type(data, G_VARIANT_TYPE_UINT64)) { + srd_err("Invalid value type: expected uint64, got %s", + g_variant_get_type_string(data)); + return SRD_ERR_ARG; + } srd_dbg("Setting session %d samplerate to %"PRIu64".", sess->session_id, g_variant_get_uint64(data));