changing its semantic without changing its name would be cumbersome.
Fix a long standing bug with by one offsets reported by valgrind around dicts.
YEAH. At least. I'm tracking this one since a *long* time.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@1614
48e7efb5-ca39-0410-a469-
dd3cf9ba447f
-static _XBT_INLINE
-void *
-xbt_memdup(const void * const ptr,
- const size_t length) {
- void * new_ptr = NULL;
-
- new_ptr = xbt_malloc(length);
- memcpy(new_ptr, ptr, length);
-
- return new_ptr;
-}
-
/*
* _xbt_nibble_to_char:
*
/*
* _xbt_nibble_to_char:
*
_xbt_dictelm_alloc(key, key_len, offset, FALSE, data, free_f, &p_new);
p_child=xbt_dynar_get_as(p_head->sub, pos, s_xbt_dictelm_t*);
_xbt_dictelm_alloc(key, key_len, offset, FALSE, data, free_f, &p_new);
p_child=xbt_dynar_get_as(p_head->sub, pos, s_xbt_dictelm_t*);
- anc_key = xbt_memdup(key, anc_key_len);
+ /* memdup the old key, taking care of the terminating NULL byte */
+ anc_key = xbt_malloc(anc_key_len+1);
+ memcpy(anc_key, key, anc_key_len);
+ anc_key[anc_key_len] = '\0';
+
_xbt_dictelm_alloc(anc_key, anc_key_len, old_offset, TRUE, NULL, NULL, &p_anc);
_xbt_dictelm_alloc(anc_key, anc_key_len, old_offset, TRUE, NULL, NULL, &p_anc);
s_xbt_dictelm_t *p_head = *pp_head;
char *key = NULL;
s_xbt_dictelm_t *p_head = *pp_head;
char *key = NULL;
- key = xbt_memdup(_key, key_len+1);
+ /* Make sure the copied key is NULL-terminated */
+ key = xbt_malloc(key_len+1);
+ memcpy(key, _key, key_len);
+ key[key_len] = '\0';
/* there is no head, create it */
if (!p_head) {
/* there is no head, create it */
if (!p_head) {