/soc/2015/mmcc/rand: f17491df15e3: Use a char* for the data buff...

Michael McConville mmcconville at mykolab.com
Tue Aug 18 09:34:04 EDT 2015


Changeset: f17491df15e3b786f08f155cd066b33c81b0d4fa
Author:	 Michael McConville <mmcconville at mykolab.com>
Date:	 2015-08-16 21:23 -0400
Branch:	 default
URL: https://hg.pidgin.im/soc/2015/mmcc/rand/rev/f17491df15e3

Description:

Use a char* for the data buffer so that we can reliably increment it

diffstat:

 libpurple/util.c |  8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diffs (32 lines):

diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -4994,6 +4994,8 @@ purple_util_random(void *buf, size_t len
 	int fd;
 	ssize_t res;
 	size_t total = 0;
+	/* allows us to increment pointer one byte at a time */
+	char *cbuf = (char*) buf;
 	PurpleSslOps *ops = purple_ssl_get_ops();
 
 	/* use SSL API if available... */
@@ -5009,7 +5011,7 @@ purple_util_random(void *buf, size_t len
 		}
 		/* this loop could become infinite, but that would be bizarre */
 		while (total < len) {
-			res = read(fd, buf, len - total);
+			res = read(fd, cbuf, len - total);
 			if (res < 0) {
 				purple_debug_error("purple_random",
 						"/dev/urandom read failed: %s", g_strerror(errno));
@@ -5017,8 +5019,8 @@ purple_util_random(void *buf, size_t len
 				return 1;
 			/* condition used to clarify danger of underflow on cast */
 			} else {
-				buf += (size_t)res;
-				total += (size_t)res;
+				cbuf += (size_t) res;
+				total += (size_t) res;
 			}
 		}
 		close(fd);



More information about the Commits mailing list