dovecot-2.2: lib: guid - centralise a 'reset to the empty value'...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Jan 5 20:20:50 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/ff30ec13fcb7
changeset: 18136:ff30ec13fcb7
user: Phil Carmody <phil at dovecot.fi>
date: Mon Jan 05 22:16:59 2015 +0200
description:
lib: guid - centralise a 'reset to the empty value' helper function
This helper just ensures that the caller never has to get the sizeof()
right. (Were a guid passed as a function parameter, mistakes could happen.)
Signed-off-by: Phil Carmody <phil at dovecot.fi>
diffstat:
src/lib/guid.h | 4 ++++
src/lib/test-guid.c | 8 ++++----
2 files changed, 8 insertions(+), 4 deletions(-)
diffs (43 lines):
diff -r 4f0f1e10cb53 -r ff30ec13fcb7 src/lib/guid.h
--- a/src/lib/guid.h Mon Jan 05 22:15:31 2015 +0200
+++ b/src/lib/guid.h Mon Jan 05 22:16:59 2015 +0200
@@ -12,6 +12,10 @@
void guid_128_generate(guid_128_t guid_r);
/* Returns TRUE if GUID is empty (not set / unknown). */
bool guid_128_is_empty(const guid_128_t guid) ATTR_PURE;
+static inline void guid_128_empty(guid_128_t guid)
+{
+ memset(guid, 0, GUID_128_SIZE);
+}
/* Returns TRUE if two GUIDs are equal. */
bool guid_128_equals(const guid_128_t guid1, const guid_128_t guid2) ATTR_PURE;
/* Copy GUID */
diff -r 4f0f1e10cb53 -r ff30ec13fcb7 src/lib/test-guid.c
--- a/src/lib/test-guid.c Mon Jan 05 22:15:31 2015 +0200
+++ b/src/lib/test-guid.c Mon Jan 05 22:16:59 2015 +0200
@@ -10,13 +10,11 @@
0xab, 0xcd, 0xef,
0xAB, 0xCD, 0xEF,
0x00, 0x00, 0x00, 0x00, 0x00 };
- guid_128_t guid1, guid2, guid3, empty_guid;
+ guid_128_t guid1, guid2, guid3;
const char *str;
char guidbuf[GUID_128_SIZE*2 + 2];
unsigned int i;
- memset(empty_guid, 0, sizeof(empty_guid));
-
test_begin("guid_128_generate()");
guid_128_generate(guid1);
guid_128_generate(guid2);
@@ -27,7 +25,9 @@
test_begin("guid_128_is_empty()");
test_assert(!guid_128_is_empty(guid1));
test_assert(!guid_128_is_empty(guid2));
- test_assert(guid_128_is_empty(empty_guid));
+ guid_128_generate(guid3);
+ guid_128_empty(guid3);
+ test_assert(guid_128_is_empty(guid3));
test_end();
test_begin("guid_128_copy()");
More information about the dovecot-cvs
mailing list