gmime r1359 - in trunk: . gmime
- From: fejj svn gnome org
- To: svn-commits-list gnome org
- Subject: gmime r1359 - in trunk: . gmime
- Date: Sun, 15 Jun 2008 13:42:40 +0000 (UTC)
Author: fejj
Date: Sun Jun 15 13:42:40 2008
New Revision: 1359
URL: http://svn.gnome.org/viewvc/gmime?rev=1359&view=rev
Log:
2008-06-15 Jeffrey Stedfast <fejj novell com>
* gmime/gmime-gpg-context.c (status_backup): Use the bitwise
nearest_pow() implementation.
Modified:
trunk/ChangeLog
trunk/gmime/gmime-gpg-context.c
Modified: trunk/gmime/gmime-gpg-context.c
==============================================================================
--- trunk/gmime/gmime-gpg-context.c (original)
+++ trunk/gmime/gmime-gpg-context.c Sun Jun 15 13:42:40 2008
@@ -1188,19 +1188,31 @@
return 0;
}
+static size_t
+nearest_pow (size_t num)
+{
+ size_t n = num > 0 ? num - 1 : 0;
+
+ n |= n >> 1;
+ n |= n >> 2;
+ n |= n >> 4;
+ n |= n >> 8;
+ n |= n >> 16;
+ n++;
+
+ return n;
+}
+
#define status_backup(gpg, start, len) G_STMT_START { \
if (gpg->statusleft <= len) { \
- unsigned int slen, soff; \
- \
- slen = soff = gpg->statusptr - gpg->statusbuf; \
- slen = slen ? slen : 1; \
+ size_t slen, soff; \
\
- while (slen < soff + len) \
- slen <<= 1; \
+ soff = gpg->statusptr - gpg->statusbuf; \
+ slen = nearest_pow (soff + len + 1); \
\
- gpg->statusbuf = g_realloc (gpg->statusbuf, slen + 1); \
+ gpg->statusbuf = g_realloc (gpg->statusbuf, slen); \
gpg->statusptr = gpg->statusbuf + soff; \
- gpg->statusleft = slen - soff; \
+ gpg->statusleft = (slen - 1) - soff; \
} \
\
memcpy (gpg->statusptr, start, len); \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]