summaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/to_str.c10
-rw-r--r--wsutil/wmem/wmem_map.c24
-rw-r--r--wsutil/wmem/wmem_map.h16
3 files changed, 28 insertions, 22 deletions
diff --git a/wsutil/to_str.c b/wsutil/to_str.c
index d15576d4..d3e41538 100644
--- a/wsutil/to_str.c
+++ b/wsutil/to_str.c
@@ -225,7 +225,10 @@ bytes_to_str_punct_maxlen(wmem_allocator_t *scope,
int truncated = 0;
ws_return_str_if(!src, scope);
- ws_return_str_if(!src_size, scope);
+
+ if (!src_size) {
+ return wmem_strdup(scope, "");
+ }
if (!punct)
return bytes_to_str_maxlen(scope, src, src_size, max_bytes_len);
@@ -264,7 +267,10 @@ bytes_to_str_maxlen(wmem_allocator_t *scope,
int truncated = 0;
ws_return_str_if(!src, scope);
- ws_return_str_if(!src_size, scope);
+
+ if (!src_size) {
+ return wmem_strdup(scope, "");
+ }
if (max_bytes_len == 0 || max_bytes_len > src_size) {
max_bytes_len = src_size;
diff --git a/wsutil/wmem/wmem_map.c b/wsutil/wmem/wmem_map.c
index ea76f455..047b8457 100644
--- a/wsutil/wmem/wmem_map.c
+++ b/wsutil/wmem/wmem_map.c
@@ -231,8 +231,8 @@ wmem_map_contains(wmem_map_t *map, const void *key)
{
wmem_map_item_t *item;
- /* Make sure we have a table */
- if (map->table == NULL) {
+ /* Make sure we have map and a table */
+ if (map == NULL || map->table == NULL) {
return false;
}
@@ -255,8 +255,8 @@ wmem_map_lookup(wmem_map_t *map, const void *key)
{
wmem_map_item_t *item;
- /* Make sure we have a table */
- if (map->table == NULL) {
+ /* Make sure we have map and a table */
+ if (map == NULL || map->table == NULL) {
return NULL;
}
@@ -279,8 +279,8 @@ wmem_map_lookup_extended(wmem_map_t *map, const void *key, const void **orig_key
{
wmem_map_item_t *item;
- /* Make sure we have a table */
- if (map->table == NULL) {
+ /* Make sure we have map and a table */
+ if (map == NULL || map->table == NULL) {
return false;
}
@@ -310,8 +310,8 @@ wmem_map_remove(wmem_map_t *map, const void *key)
wmem_map_item_t **item, *tmp;
void *value;
- /* Make sure we have a table */
- if (map->table == NULL) {
+ /* Make sure we have map and a table */
+ if (map == NULL || map->table == NULL) {
return NULL;
}
@@ -341,8 +341,8 @@ wmem_map_steal(wmem_map_t *map, const void *key)
{
wmem_map_item_t **item, *tmp;
- /* Make sure we have a table */
- if (map->table == NULL) {
+ /* Make sure we have map and a table */
+ if (map == NULL || map->table == NULL) {
return false;
}
@@ -395,7 +395,7 @@ wmem_map_foreach(wmem_map_t *map, GHFunc foreach_func, void * user_data)
unsigned i;
/* Make sure we have a table */
- if (map->table == NULL) {
+ if (map == NULL || map->table == NULL) {
return;
}
@@ -415,7 +415,7 @@ wmem_map_foreach_remove(wmem_map_t *map, GHRFunc foreach_func, void * user_data)
unsigned i, deleted = 0;
/* Make sure we have a table */
- if (map->table == NULL) {
+ if (map == NULL || map->table == NULL) {
return 0;
}
diff --git a/wsutil/wmem/wmem_map.h b/wsutil/wmem/wmem_map.h
index a6886dd4..cb296fb4 100644
--- a/wsutil/wmem/wmem_map.h
+++ b/wsutil/wmem/wmem_map.h
@@ -79,7 +79,7 @@ G_GNUC_MALLOC;
/** Inserts a value into the map.
*
- * @param map The map to insert into.
+ * @param map The map to insert into. Must not be NULL.
* @param key The key to insert by.
* @param value The value to insert.
* @return The previous value stored at this key if any, or NULL.
@@ -90,7 +90,7 @@ wmem_map_insert(wmem_map_t *map, const void *key, void *value);
/** Check if a value is in the map.
*
- * @param map The map to search in.
+ * @param map The map to search in. May be NULL.
* @param key The key to lookup.
* @return true if the key is in the map, otherwise false.
*/
@@ -100,7 +100,7 @@ wmem_map_contains(wmem_map_t *map, const void *key);
/** Lookup a value in the map.
*
- * @param map The map to search in.
+ * @param map The map to search in. May be NULL.
* @param key The key to lookup.
* @return The value stored at the key if any, or NULL.
*/
@@ -111,7 +111,7 @@ wmem_map_lookup(wmem_map_t *map, const void *key);
/** Lookup a value in the map, returning the key, value, and a boolean which
* is true if the key is found.
*
- * @param map The map to search in.
+ * @param map The map to search in. May be NULL.
* @param key The key to lookup.
* @param orig_key (optional) The key that was determined to be a match, if any.
* @param value (optional) The value stored at the key, if any.
@@ -124,7 +124,7 @@ wmem_map_lookup_extended(wmem_map_t *map, const void *key, const void **orig_key
/** Remove a value from the map. If no value is stored at that key, nothing
* happens.
*
- * @param map The map to remove from.
+ * @param map The map to remove from. May be NULL.
* @param key The key of the value to remove.
* @return The (removed) value stored at the key if any, or NULL.
*/
@@ -135,7 +135,7 @@ wmem_map_remove(wmem_map_t *map, const void *key);
/** Remove a key and value from the map but does not destroy (free) them. If no
* value is stored at that key, nothing happens.
*
- * @param map The map to remove from.
+ * @param map The map to remove from. May be NULL.
* @param key The key of the value to remove.
* @return true if key is found false if not.
*/
@@ -157,7 +157,7 @@ wmem_map_get_keys(wmem_allocator_t *list_allocator, wmem_map_t *map);
* of the calls is unpredictable, since it is based on the internal
* storage of data.
*
- * @param map The map to use
+ * @param map The map to use. May be NULL.
* @param foreach_func the function to call for each key/value pair
* @param user_data user data to pass to the function
*/
@@ -170,7 +170,7 @@ wmem_map_foreach(wmem_map_t *map, GHFunc foreach_func, void * user_data);
* the map. The order of the calls is unpredictable, since it is
* based on the internal storage of data.
*
- * @param map The map to use
+ * @param map The map to use. May be NULL.
* @param foreach_func the function to call for each key/value pair
* @param user_data user data to pass to the function
* @return The number of items removed