Commit Diff


commit - c6f9745ecc2be61996aecd22e87e9e028eef1907
commit + 72d0ec484e076adae167151a54af4e58ad39b647
blob - d14b04eed473e9ae7b3a22dfdca6431d1ed5174c
blob + cb42223006577b8071076b8753890c9fe56df50e
--- table_static.c
+++ table_static.c
@@ -40,8 +40,8 @@ struct table_backend table_static = {
 };
 
 struct kp {
-	char	*key;
 	char	*val;
+	char	 key[];
 };
 
 static void *
@@ -83,8 +83,11 @@ table_static_add(struct table *t, const char *key, con
 	struct kp	*kp;
 	unsigned int	 slot;
 
-	kp = xcalloc(1, sizeof(*kp));
-	kp->key = xstrdup(key);
+	if (key == NULL)
+		return -1;
+
+	kp = xcalloc(1, sizeof(*kp) + strlen(key) + 1);
+	strcpy(kp->key, key);
 	if (val != NULL)
 		kp->val = xstrdup(val);
 
@@ -100,24 +103,12 @@ table_static_lookup(struct table *t, const char *key, 
 	struct kp	*kp;
 	unsigned int	 slot;
 
-#if 0
 	slot = ohash_qlookup(t->t_handle, key);
 	if ((kp = ohash_find(t->t_handle, slot)) == NULL)
 		return -1;
 
 	*ret_val = xstrdup(kp->val);
 	return 0;
-#endif
-
-	for (kp = ohash_first(t->t_handle, &slot);
-	     kp != NULL;
-	     kp = ohash_next(t->t_handle, &slot)) {
-		if (!strcmp(kp->key, key)) {
-			*ret_val = xstrdup(kp->val);
-			return 0;
-		}
-	}
-	return -1;
 }
 
 static void