Revision: 1920 http://geany.svn.sourceforge.net/geany/?rev=1920&view=rev Author: ntrel Date: 2007-09-28 10:06:09 -0700 (Fri, 28 Sep 2007)
Log Message: ----------- Fix a possible segfault with vStringPut() - backported from CTags 5.7. This appears to fix a segfault on Windows 2000 when loading tagmanager/c.c. Also adds vStringChop() - chop last character from string.
Modified Paths: -------------- trunk/ChangeLog trunk/tagmanager/vstring.c trunk/tagmanager/vstring.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-09-28 16:32:28 UTC (rev 1919) +++ trunk/ChangeLog 2007-09-28 17:06:09 UTC (rev 1920) @@ -11,6 +11,11 @@ Add documentation for --no-preprocessing option. * src/keybindings.c: Add Project Properties menu accelerator. + * tagmanager/vstring.h, tagmanager/vstring.c: + Fix a possible segfault with vStringPut() - backported from CTags + 5.7. This appears to fix a segfault on Windows 2000 when loading + tagmanager/c.c. + It also adds vStringChop() - chop last character from string.
2007-09-27 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/tagmanager/vstring.c =================================================================== --- trunk/tagmanager/vstring.c 2007-09-28 16:32:28 UTC (rev 1919) +++ trunk/tagmanager/vstring.c 2007-09-28 17:06:09 UTC (rev 1920) @@ -1,6 +1,6 @@ /* * -* Copyright (c) 1998-2001, Darren Hiebert +* Copyright (c) 1998-2002, Darren Hiebert * * This source code is released for free distribution under the terms of the * GNU General Public License. @@ -58,7 +58,7 @@ { string->length = 0; string->buffer [0] = '\0'; - DebugStatement ( clearString (string->buffer, string->size); ) + DebugStatement ( memset (string->buffer, 0, string->size); ) }
extern void vStringDelete (vString *const string) @@ -84,26 +84,35 @@ return string; }
+#ifndef VSTRING_PUTC_MACRO extern void vStringPut (vString *const string, const int c) { - if (string->length == string->size) /* check for buffer overflow */ - vStringAutoResize (string); + if (string->length + 1 == string->size) /* check for buffer overflow */ + vStringAutoResize (string);
string->buffer [string->length] = c; if (c != '\0') - string->length++; + string->buffer [++string->length] = '\0'; } +#endif
extern void vStringCatS (vString *const string, const char *const s) { +#if 1 + const size_t len = strlen (s); + while (string->length + len + 1 >= string->size)/* check for buffer overflow */ + vStringAutoResize (string); + strcpy (string->buffer + string->length, s); + string->length += len; +#else const char *p = s; - do - vStringPut (string, *p); + vStringPut (string, *p); while (*p++ != '\0'); +#endif }
-extern vString *vStringNewCopy (vString *const string) +extern vString *vStringNewCopy (const vString *const string) { vString *vs = vStringNew (); vStringCatS (vs, string->buffer); @@ -117,8 +126,8 @@ return vs; }
-extern void vStringNCatS (vString *const string, const char *const s, - const size_t length) +extern void vStringNCatS ( + vString *const string, const char *const s, const size_t length) { const char *p = s; size_t remain = length; @@ -170,20 +179,31 @@ } }
+/* Chop last character from string. + */ +extern void vStringChop (vString *const string) +{ + if (string->length > 0) + { + --string->length; + string->buffer [string->length] = '\0'; + } +} + extern void vStringCopyS (vString *const string, const char *const s) { vStringClear (string); vStringCatS (string, s); }
-extern void vStringNCopyS (vString *const string, const char *const s, - const size_t length) +extern void vStringNCopyS ( + vString *const string, const char *const s, const size_t length) { vStringClear (string); vStringNCatS (string, s, length); }
-extern void vStringCopyToLower (vString *const dest, vString *const src) +extern void vStringCopyToLower (vString *const dest, const vString *const src) { const size_t length = src->length; const char *s = src->buffer; @@ -207,4 +227,4 @@ string->length = strlen (string->buffer); }
-/* vi:set tabstop=8 shiftwidth=4: */ +/* vi:set tabstop=4 shiftwidth=4: */
Modified: trunk/tagmanager/vstring.h =================================================================== --- trunk/tagmanager/vstring.h 2007-09-28 16:32:28 UTC (rev 1919) +++ trunk/tagmanager/vstring.h 2007-09-28 17:06:09 UTC (rev 1920) @@ -1,5 +1,5 @@ /* -* Copyright (c) 1998-2001, Darren Hiebert +* Copyright (c) 1998-2002, Darren Hiebert * * This source code is released for free distribution under the terms of the * GNU General Public License. @@ -21,6 +21,16 @@ /* * MACROS */ +#ifndef DEBUG +# define VSTRING_PUTC_MACRO 1 +#endif +#ifdef VSTRING_PUTC_MACRO +#define vStringPut(s,c) \ + (void)(((s)->length + 1 == (s)->size ? vStringAutoResize (s) : 0), \ + ((s)->buffer [(s)->length] = (c)), \ + ((c) == '\0' ? 0 : ((s)->buffer [++(s)->length] = '\0'))) +#endif + #define vStringValue(vs) ((vs)->buffer) #define vStringItem(vs,i) ((vs)->buffer[i]) #define vStringLength(vs) ((vs)->length) @@ -51,19 +61,22 @@ extern void vStringClear (vString *const string); extern vString *vStringNew (void); extern void vStringDelete (vString *const string); +#ifndef VSTRING_PUTC_MACRO extern void vStringPut (vString *const string, const int c); +#endif extern void vStringStripNewline (vString *const string); extern void vStringStripLeading (vString *const string); +extern void vStringChop (vString *const string); extern void vStringStripTrailing (vString *const string); extern void vStringCatS (vString *const string, const char *const s); extern void vStringNCatS (vString *const string, const char *const s, const size_t length); -extern vString *vStringNewCopy (vString *const string); +extern vString *vStringNewCopy (const vString *const string); extern vString *vStringNewInit (const char *const s); extern void vStringCopyS (vString *const string, const char *const s); extern void vStringNCopyS (vString *const string, const char *const s, const size_t length); -extern void vStringCopyToLower (vString *const dest, vString *const src); +extern void vStringCopyToLower (vString *const dest, const vString *const src); extern void vStringSetLength (vString *const string);
#endif /* _VSTRING_H */
-/* vi:set tabstop=8 shiftwidth=4: */ +/* vi:set tabstop=4 shiftwidth=4: */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.