X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fcaptoinfo.c;h=60fab3bddc8d4206a3abf17254dc9fba5e56a68d;hp=e2c81308e2c1a3f2bbbb83b20c19880578b8a836;hb=fc79b49bd8a9c5e4db287514cdac46e1691cf48a;hpb=a8987e73ec254703634802b4f7ee30d3a485524d diff --git a/ncurses/tinfo/captoinfo.c b/ncurses/tinfo/captoinfo.c index e2c81308..60fab3bd 100644 --- a/ncurses/tinfo/captoinfo.c +++ b/ncurses/tinfo/captoinfo.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2002,2003 Free Software Foundation, Inc. * + * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,6 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim 1992,1995 * * and: Eric S. Raymond * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -92,7 +93,7 @@ #include #include -MODULE_ID("$Id: captoinfo.c,v 1.45 2003/11/08 21:28:04 tom Exp $") +MODULE_ID("$Id: captoinfo.c,v 1.53 2009/03/28 20:44:23 tom Exp $") #define MAX_PUSHED 16 /* max # args we can push onto the stack */ @@ -127,7 +128,7 @@ save_string(char *d, const char *const s) size_t have = (d - my_string); size_t need = have + strlen(s) + 2; if (need > my_length) { - my_string = (char *) realloc(my_string, my_length = (need + need)); + my_string = (char *) _nc_doalloc(my_string, my_length = (need + need)); if (my_string == 0) _nc_err_abort(MSG_NO_MEMORY); d = my_string + have; @@ -136,7 +137,7 @@ save_string(char *d, const char *const s) return d + strlen(d); } -static inline char * +static NCURSES_INLINE char * save_char(char *s, int c) { static char temp[2]; @@ -148,7 +149,7 @@ static void push(void) /* push onstack on to the stack */ { - if (stackptr > MAX_PUSHED) + if (stackptr >= MAX_PUSHED) _nc_warning("string too complex to convert"); else stack[stackptr++] = onstack; @@ -182,7 +183,7 @@ cvtchar(register const char *sp) case '$': case '\\': case '%': - c = *sp; + c = (unsigned char) (*sp); len = 2; break; case '\0': @@ -200,7 +201,7 @@ cvtchar(register const char *sp) } break; default: - c = *sp; + c = (unsigned char) (*sp); len = 2; break; } @@ -210,7 +211,7 @@ cvtchar(register const char *sp) len = 2; break; default: - c = *sp; + c = (unsigned char) (*sp); len = 1; } if (isgraph(c) && c != ',' && c != '\'' && c != '\\' && c != ':') { @@ -276,7 +277,7 @@ getparm(int parm, int n) * % translations if 1 * pad translations if >=0 */ -char * +NCURSES_EXPORT(char *) _nc_captoinfo(const char *cap, const char *s, int const parameterized) { const char *capstart; @@ -636,7 +637,7 @@ save_tc_inequality(char *bufptr, int c1, int c2) * Convert a terminfo string to termcap format. Parameters are as in * _nc_captoinfo(). */ -char * +NCURSES_EXPORT(char *) _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameterized) { int seenone = 0, seentwo = 0, saw_m = 0, saw_n = 0; @@ -678,6 +679,7 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameteriz --str; } else if (str[0] == '%' && str[1] == '%') { /* escaped '%' */ bufptr = save_string(bufptr, "%%"); + ++str; } else if (*str != '%' || (parameterized < 1)) { bufptr = save_char(bufptr, *str); } else if (sscanf(str, "%%?%%{%d}%%>%%t%%{%d}%%+%%;", &c1, &c2) == 2) { @@ -786,6 +788,11 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameteriz } /* endswitch (*str) */ } /* endelse (*str == '%') */ + /* + * 'str' always points to the end of what was scanned in this step, + * but that may not be the end of the string. + */ + assert(str != 0); if (*str == '\0') break; @@ -833,4 +840,13 @@ main(int argc, char *argv[]) } #endif /* MAIN */ -/* captoinfo.c ends here */ +#if NO_LEAKS +NCURSES_EXPORT(void) +_nc_captoinfo_leaks(void) +{ + if (my_string != 0) { + FreeAndNull(my_string); + } + my_length = 0; +} +#endif