[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[SCM] libgnokii and core programs branch, master, updated. rel_0_6_29-27
From: |
Daniele Forsi |
Subject: |
[SCM] libgnokii and core programs branch, master, updated. rel_0_6_29-279-g7eb6859 |
Date: |
Mon, 11 Jul 2011 20:10:09 +0000 |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "libgnokii and core programs".
The branch, master has been updated
via 7eb6859db97074ac3ae2054a9e195f366f2541ef (commit)
from 08a87450666d84e5e346df709eb9043287533084 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/gnokii.git/commit/?id=7eb6859db97074ac3ae2054a9e195f366f2541ef
commit 7eb6859db97074ac3ae2054a9e195f366f2541ef
Author: Daniele Forsi <address@hidden>
Date: Mon Jul 11 22:01:35 2011 +0200
Fix off by ones in vcard writer when folding lines
The first folded line contains 75 (not 76) characters and the other
lines can contain only 74 characters to make room for the leading
space.
See http://www.ietf.org/rfc/rfc2425.txt sections 5.8.1 and 5.8.2.
diff --git a/common/vcard.c b/common/vcard.c
index 53e5a91..22c2c2e 100644
--- a/common/vcard.c
+++ b/common/vcard.c
@@ -84,41 +84,45 @@ static void vcard_append_printf(vcard_string *str, const
char *fmt, ...)
{
char buf[1024];
va_list ap;
- int len, lines, l;
+ size_t len, to_copy;
+ int lines, l;
char *s = "\r\n";
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
- /* Number of lines needed */
- lines = strlen(buf) / 76 + 1;
- /* 3 characters for each line beyond the first one,
- * plus the length of the buffer
- * plus the line feed and the nul byte to finish it off */
- len = (lines - 1) * 3 + strlen(buf) + 3;
-
- /* The first malloc must have a nul byte at the end */
- if (str->str)
- str->str = realloc(str->str, len + str->len);
- else
- str->str = realloc(str->str, len + 1);
- if (str->end == NULL)
- str->end = str->str;
+ /* Split lines according to sections 5.8.1 and 5.8.2 of
http://www.ietf.org/rfc/rfc2425.txt */
+ len = strlen(buf);
+ /* Number of lines needed after the first one:
+ * at most 75 characters in the first line
+ * at most space+74 characters in each line beyond the first */
+ if (len < 2)
+ lines = 0;
else
- str->end = str->str + str->len;
+ lines = (len - 75 + 73) / 74;
+ /* Current string length
+ * plus length of the string to be appended
+ * plus 2 characters for \r\n at the end of the first line,
+ * plus 3 characters for space at the beginning and \r\n at the end of
each line beyond the first
+ * and a NUL byte to finish it off */
+ str->str = realloc(str->str, str->len + len + 2 + lines * 3 + 1);
+ str->end = str->str + str->len;
+
+ to_copy = GNOKII_MIN(75, len);
+ memcpy(str->end, buf, to_copy);
+ str->end += to_copy;
+ len -= to_copy;
for (l = 0; l < lines; l++) {
- int to_copy;
-
- to_copy = GNOKII_MIN(76, strlen(buf) - 76 * l);
- memcpy(str->end, buf + 76 * l, to_copy);
- str->end = str->end + to_copy;
- if (l != lines - 1) {
- char *s = "\r\n ";
- memcpy(str->end, s, 3);
- str->end += 3;
- }
+ char *s = "\r\n ";
+
+ memcpy(str->end, s, 3);
+ str->end += 3;
+ to_copy = GNOKII_MIN(74, len);
+ memcpy(str->end, buf + 75 + 74 * l, to_copy);
+ str->end += to_copy;
+ len -= to_copy;
}
memcpy(str->end, s, 2);
-----------------------------------------------------------------------
Summary of changes:
common/vcard.c | 56 ++++++++++++++++++++++++++++++--------------------------
1 files changed, 30 insertions(+), 26 deletions(-)
hooks/post-receive
--
libgnokii and core programs
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [SCM] libgnokii and core programs branch, master, updated. rel_0_6_29-279-g7eb6859,
Daniele Forsi <=