Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make object keys NUL-terminated.

This wastes one byte of storage per object, but makes it more
convenient to use keys as strings.

darcs-hash:20080520223936-4cc09-67d30b3321b91882b1e773ee121ce8b31b63f6e0.gz
  • Loading branch information...
commit 479a82444412e532785a505acaf3be5cb5e4d08f 1 parent 3c21d7f
@jech jech authored
Showing with 5 additions and 2 deletions.
  1. +4 −1 object.c
  2. +1 −1  object.h
View
5 object.c
@@ -197,12 +197,15 @@ makeObject(int type, const void *key, int key_size, int public, int fromdisk,
object->type = type;
object->request = request;
object->request_closure = request_closure;
- object->key = malloc(key_size);
+ object->key = malloc(key_size + 1);
if(object->key == NULL) {
free(object);
return NULL;
}
memcpy(object->key, key, key_size);
+ /* In order to make it more convenient to use keys as strings,
+ they are NUL-terminated. */
+ object->key[key_size] = '\0';
object->key_size = key_size;
object->flags = (public?OBJECT_PUBLIC:0) | OBJECT_INITIAL;
if(public) {
View
2  object.h
@@ -50,7 +50,7 @@ typedef struct _Object {
unsigned char type;
RequestFunction request;
void *request_closure;
- void *key;
+ char *key;
unsigned short key_size;
unsigned short flags;
unsigned short code;
Please sign in to comment.
Something went wrong with that request. Please try again.