[libdmapsharing] Handle invalid content codes in dmap_content_code_dmap_type
- From: W. Michael Petullo <wmpetullo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdmapsharing] Handle invalid content codes in dmap_content_code_dmap_type
- Date: Tue, 5 Dec 2017 04:07:08 +0000 (UTC)
commit 7b97dbb4703639d1fc9d2eb9ea4576669508b013
Author: W. Michael Petullo <mike flyn org>
Date: Mon Dec 4 22:55:04 2017 -0500
Handle invalid content codes in dmap_content_code_dmap_type
Signed-off-by: W. Michael Petullo <mike flyn org>
libdmapsharing/dmap-structure.c | 17 ++++++++++++++---
libdmapsharing/dmap-structure.h | 3 ++-
2 files changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/libdmapsharing/dmap-structure.c b/libdmapsharing/dmap-structure.c
index c8e10c6..e68bde2 100644
--- a/libdmapsharing/dmap-structure.c
+++ b/libdmapsharing/dmap-structure.c
@@ -357,7 +357,15 @@ dmap_content_code_name (DMAPContentCode code)
DMAPType
dmap_content_code_dmap_type (DMAPContentCode code)
{
- return cc_defs[code - 1].type;
+ DMAPType type = DMAP_TYPE_INVALID;
+
+ if (code < sizeof cc_defs / sizeof(DMAPContentCodeDefinition)) {
+ type = cc_defs[code - 1].type;
+ } else {
+ g_warning("Invalid content code: %d\n", code);
+ }
+
+ return type;
}
const gchar *
@@ -386,6 +394,7 @@ dmap_content_code_gtype (DMAPContentCode code)
case DMAP_TYPE_POINTER:
return G_TYPE_POINTER;
case DMAP_TYPE_CONTAINER:
+ case DMAP_TYPE_INVALID:
default:
return G_TYPE_NONE;
}
@@ -482,6 +491,7 @@ dmap_structure_node_serialize (GNode * node, GByteArray * array)
break;
}
case DMAP_TYPE_CONTAINER:
+ case DMAP_TYPE_INVALID:
default:
break;
}
@@ -868,8 +878,9 @@ dmap_structure_find_node (GNode * structure, DMAPContentCode code)
static void
dmap_item_free (DMAPStructureItem * item)
{
- if (dmap_content_code_dmap_type (item->content_code) !=
- DMAP_TYPE_CONTAINER) {
+ DMAPType type = dmap_content_code_dmap_type (item->content_code);
+
+ if (DMAP_TYPE_INVALID != type && DMAP_TYPE_CONTAINER != type) {
g_value_unset (&(item->content));
}
diff --git a/libdmapsharing/dmap-structure.h b/libdmapsharing/dmap-structure.h
index e5d59ad..24a9a95 100644
--- a/libdmapsharing/dmap-structure.h
+++ b/libdmapsharing/dmap-structure.h
@@ -228,7 +228,8 @@ typedef enum
DMAP_TYPE_DATE = 0x000A,
DMAP_TYPE_VERSION = 0x000B,
DMAP_TYPE_CONTAINER = 0x000C,
- DMAP_TYPE_POINTER = 0x002A
+ DMAP_TYPE_POINTER = 0x002A,
+ DMAP_TYPE_INVALID = 0xFFFF
} DMAPType;
typedef struct _DMAPContentCodeDefinition DMAPContentCodeDefinition;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]