[asterisk-commits] mmichelson: branch mmichelson/uuid r376724 - /team/mmichelson/uuid/main/uuid.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Nov 28 09:47:18 CST 2012


Author: mmichelson
Date: Wed Nov 28 09:47:15 2012
New Revision: 376724

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=376724
Log:
Make some miscellaneous tweaks:

Addresses Walter Doekes' feedback
* Change ast_calloc to ast_malloc
* Make sure uuid_parse() succeeds before returning a value
* Add comment explaining UUID_STR_LEN

There are some other changes
* Improved some grammar in comments
* Refer to proper RFC section for random number UUIDs


Modified:
    team/mmichelson/uuid/main/uuid.c

Modified: team/mmichelson/uuid/main/uuid.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/uuid/main/uuid.c?view=diff&rev=376724&r1=376723&r2=376724
==============================================================================
--- team/mmichelson/uuid/main/uuid.c (original)
+++ team/mmichelson/uuid/main/uuid.c Wed Nov 28 09:47:15 2012
@@ -28,6 +28,7 @@
 #include "asterisk/strings.h"
 #include "asterisk/logger.h"
 
+/*! The length of a UUID string plus terminating null byte */
 #define UUID_STR_LEN 37
 
 struct ast_uuid {
@@ -36,7 +37,7 @@
 
 struct ast_uuid *ast_uuid_generate(void)
 {
-	struct ast_uuid *uuid = ast_calloc(1, sizeof(*uuid));
+	struct ast_uuid *uuid = ast_malloc(sizeof(*uuid));
 
 	if (!uuid) {
 		return NULL;
@@ -48,7 +49,7 @@
 	 * attempts to use either /dev/urandom or /dev/random to generate random values.
 	 * If these resources are unavailable, then random numbers will be generated
 	 * using C library calls to generate pseudorandom numbers.
-	 * This method of generating UUIDs corresponds to section 4.2 of RFC 4122.
+	 * This method of generating UUIDs corresponds to section 4.4 of RFC 4122.
 	 *
 	 * uuid_generate_time() creates a UUID based on the current time plus
 	 * a system identifier (MAC address of the ethernet interface). This
@@ -78,17 +79,17 @@
 	 *     run with permissions that will allow for the daemon to be launched in
 	 *     the expected directories.
 	 *
-	 *     c) Once the daemon is running, concurrent requests for UUIDs is thread-safe.
+	 *     c) Once the daemon is running, concurrent requests for UUIDs are thread-safe.
 	 *     However, the actual launching of the daemon is not thread-safe since libuuid
 	 *     uses no synchronization primitives to ensure that only one thread (or process)
 	 *     launches the daemon.
 	 *
 	 *     d) When libuuid launches the daemon, it sets an inactivity timer.
 	 *     If no UUID generation requests are issued in that time period,
-	 *     then the daemon will stop. If a new request should occur after the daemon
-	 *     exits, then the daemon will be relaunched. Given point c), we could not
+	 *     then the daemon will exit. If a new request should occur after the daemon
+	 *     exits, then the daemon will be relaunched. Given point c), we cannot
 	 *     necessarily guarantee the thread-safety of time-based UUID generation since
-	 *     we could not necessarily guarantee the daemon was running as we expected.
+	 *     we cannot necessarily guarantee the daemon is running as we expect.
 	 *     We could set up a watchdog thread to generate UUIDs at regular intervals to
 	 *     prevent the daemon from exiting, but frankly, that sucks.
 	 *
@@ -112,17 +113,23 @@
 
 struct ast_uuid *ast_str_to_uuid(const struct ast_str *str)
 {
-	struct ast_uuid *uuid = ast_calloc(1, sizeof(*uuid));
+	struct ast_uuid *uuid = ast_malloc(sizeof(*uuid));
+	int res;
 	if (!uuid) {
 		return NULL;
 	}
-	uuid_parse(ast_str_buffer(str), uuid->uu);
+	res = uuid_parse(ast_str_buffer(str), uuid->uu);
+	if (res) {
+		ast_log(LOG_WARNING, "Unable to convert string %s into a UUID\n", ast_str_buffer(str));
+		ast_free(uuid);
+		return NULL;
+	}
 	return uuid;
 }
 
 struct ast_uuid *ast_uuid_copy(const struct ast_uuid *src)
 {
-	struct ast_uuid *dst = ast_calloc(1, sizeof(*dst));
+	struct ast_uuid *dst = ast_malloc(sizeof(*dst));
 	if (!dst) {
 		return NULL;
 	}




More information about the asterisk-commits mailing list