If the buffer is too small, making it twice as big does not guarantee it
* e-html-utils.c (check_size): If the buffer is too small, making it twice as big does not guarantee it will be big enough. "Duh". Also, a bunch of the check_size calls don't seem to be taking trailing NULs into account, so add in a +1 here. svn path=/trunk/; revision=9549
This commit is contained in:
@ -1,3 +1,10 @@
|
|||||||
|
2001-04-24 Dan Winship <danw@ximian.com>
|
||||||
|
|
||||||
|
* e-html-utils.c (check_size): If the buffer is too small, making
|
||||||
|
it twice as big does not guarantee it will be big enough. "Duh".
|
||||||
|
Also, a bunch of the check_size calls don't seem to be taking
|
||||||
|
trailing NULs into account, so add in a +1 here.
|
||||||
|
|
||||||
2001-04-24 Kjartan Maraas <kmaraas@gnome.org>
|
2001-04-24 Kjartan Maraas <kmaraas@gnome.org>
|
||||||
|
|
||||||
* e-gui-utils.c, e-memory, e-msgport.c, e-pilot-map, e-sexp.c:
|
* e-gui-utils.c, e-memory, e-msgport.c, e-pilot-map, e-sexp.c:
|
||||||
|
@ -23,17 +23,17 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <unicode.h>
|
#include <gal/unicode/gunicode.h>
|
||||||
|
|
||||||
#include "e-html-utils.h"
|
#include "e-html-utils.h"
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
check_size (char **buffer, int *buffer_size, char *out, int len)
|
check_size (char **buffer, int *buffer_size, char *out, int len)
|
||||||
{
|
{
|
||||||
if (out + len > *buffer + *buffer_size) {
|
if (out + len + 1> *buffer + *buffer_size) {
|
||||||
int index = out - *buffer;
|
int index = out - *buffer;
|
||||||
|
|
||||||
*buffer_size *= 2;
|
*buffer_size = MAX (index + len + 1, *buffer_size * 2);
|
||||||
*buffer = g_realloc (*buffer, *buffer_size);
|
*buffer = g_realloc (*buffer, *buffer_size);
|
||||||
out = *buffer + index;
|
out = *buffer + index;
|
||||||
}
|
}
|
||||||
@ -122,7 +122,7 @@ email_address_extract (const unsigned char **text)
|
|||||||
static gboolean
|
static gboolean
|
||||||
is_citation (const unsigned char *c, gboolean saw_citation)
|
is_citation (const unsigned char *c, gboolean saw_citation)
|
||||||
{
|
{
|
||||||
unicode_char_t u;
|
gunichar u;
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
/* A line that starts with a ">" is a citation, unless it's
|
/* A line that starts with a ">" is a citation, unless it's
|
||||||
@ -150,11 +150,11 @@ is_citation (const unsigned char *c, gboolean saw_citation)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check for "Rupert> " and the like... */
|
/* Check for "Rupert> " and the like... */
|
||||||
for (i = 0; c && *c && *c != '\n' && i < 10; i ++, c = unicode_next_utf8 (c)) {
|
for (i = 0; c && *c && *c != '\n' && i < 10; i ++, c = g_utf8_next_char (c)) {
|
||||||
unicode_get_utf8 (c, &u);
|
u = g_utf8_get_char (c);
|
||||||
if (u == '>')
|
if (u == '>')
|
||||||
return TRUE;
|
return TRUE;
|
||||||
if (!unicode_isalnum (u))
|
if (!g_unichar_isalnum (u))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -219,8 +219,8 @@ e_text_to_html_full (const char *input, unsigned int flags, guint32 color)
|
|||||||
|
|
||||||
col = 0;
|
col = 0;
|
||||||
|
|
||||||
for (cur = input; cur && *cur; cur = unicode_next_utf8 (cur)) {
|
for (cur = input; cur && *cur; cur = g_utf8_next_char (cur)) {
|
||||||
unicode_char_t u;
|
gunichar u;
|
||||||
|
|
||||||
if (flags & E_TEXT_TO_HTML_MARK_CITATION && col == 0) {
|
if (flags & E_TEXT_TO_HTML_MARK_CITATION && col == 0) {
|
||||||
saw_citation = is_citation (cur, saw_citation);
|
saw_citation = is_citation (cur, saw_citation);
|
||||||
@ -247,8 +247,8 @@ e_text_to_html_full (const char *input, unsigned int flags, guint32 color)
|
|||||||
cur++;
|
cur++;
|
||||||
}
|
}
|
||||||
|
|
||||||
unicode_get_utf8 (cur, &u);
|
u = g_utf8_get_char (cur);
|
||||||
if (unicode_isalpha (u) &&
|
if (g_unichar_isalpha (u) &&
|
||||||
(flags & E_TEXT_TO_HTML_CONVERT_URLS)) {
|
(flags & E_TEXT_TO_HTML_CONVERT_URLS)) {
|
||||||
char *tmpurl = NULL, *refurl = NULL, *dispurl = NULL;
|
char *tmpurl = NULL, *refurl = NULL, *dispurl = NULL;
|
||||||
|
|
||||||
@ -265,7 +265,7 @@ e_text_to_html_full (const char *input, unsigned int flags, guint32 color)
|
|||||||
}
|
}
|
||||||
} else if (!strncasecmp (cur, "www.", 4) &&
|
} else if (!strncasecmp (cur, "www.", 4) &&
|
||||||
(*(cur + 4) < 0x80) &&
|
(*(cur + 4) < 0x80) &&
|
||||||
unicode_isalnum (*(cur + 4))) {
|
g_unichar_isalnum (*(cur + 4))) {
|
||||||
tmpurl = url_extract (&cur, FALSE);
|
tmpurl = url_extract (&cur, FALSE);
|
||||||
dispurl = e_text_to_html (tmpurl, 0);
|
dispurl = e_text_to_html (tmpurl, 0);
|
||||||
refurl = g_strdup_printf ("http://%s",
|
refurl = g_strdup_printf ("http://%s",
|
||||||
@ -287,10 +287,10 @@ e_text_to_html_full (const char *input, unsigned int flags, guint32 color)
|
|||||||
|
|
||||||
if (!*cur)
|
if (!*cur)
|
||||||
break;
|
break;
|
||||||
unicode_get_utf8 (cur, &u);
|
u = g_utf8_get_char (cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unicode_isalpha (u)
|
if (g_unichar_isalpha (u)
|
||||||
&& (flags & E_TEXT_TO_HTML_CONVERT_ADDRESSES)
|
&& (flags & E_TEXT_TO_HTML_CONVERT_ADDRESSES)
|
||||||
&& is_email_address (cur)) {
|
&& is_email_address (cur)) {
|
||||||
gchar *addr = NULL, *dispaddr = NULL;
|
gchar *addr = NULL, *dispaddr = NULL;
|
||||||
@ -311,11 +311,11 @@ e_text_to_html_full (const char *input, unsigned int flags, guint32 color)
|
|||||||
|
|
||||||
if (!*cur)
|
if (!*cur)
|
||||||
break;
|
break;
|
||||||
unicode_get_utf8 (cur, &u);
|
u = g_utf8_get_char (cur);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (u == (unicode_char_t)-1) {
|
if (u == (gunichar)-1) {
|
||||||
/* Sigh. Someone sent undeclared 8-bit data.
|
/* Sigh. Someone sent undeclared 8-bit data.
|
||||||
* Assume it's iso-8859-1.
|
* Assume it's iso-8859-1.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user