X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=menu%2Fm_item_new.c;h=1e7950db2f51a551f6ac1b3aef57f3639f393db3;hp=185e2dca6801ecc59583098bd5071878b05b0d3a;hb=54d0d62f0eb759e3c623a215d98ddebccca64488;hpb=55ccd2b959766810cf7db8d1c4462f338ce0afc8 diff --git a/menu/m_item_new.c b/menu/m_item_new.c index 185e2dca..1e7950db 100644 --- a/menu/m_item_new.c +++ b/menu/m_item_new.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc. * + * Copyright 2020 Thomas E. Dickey * + * Copyright 1998-2010,2012 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 * @@ -39,10 +40,12 @@ #include "menu.priv.h" #if USE_WIDEC_SUPPORT +#if HAVE_WCTYPE_H #include #endif +#endif -MODULE_ID("$Id: m_item_new.c,v 1.25 2005/04/16 22:24:38 tom Exp $") +MODULE_ID("$Id: m_item_new.c,v 1.34 2020/02/02 23:34:34 tom Exp $") /*--------------------------------------------------------------------------- | Facility : libnmenu @@ -60,19 +63,19 @@ Is_Printable_String(const char *s) int result = TRUE; #if USE_WIDEC_SUPPORT - int count = mbstowcs(0, s, 0); + int count = (int)mbstowcs(0, s, 0); wchar_t *temp = 0; assert(s); if (count > 0 - && (temp = typeCalloc(wchar_t, (2 + count))) != 0) + && (temp = typeCalloc(wchar_t, (2 + (unsigned)count))) != 0) { int n; mbstowcs(temp, s, (unsigned)count); for (n = 0; n < count; ++n) - if (!iswprint(temp[n])) + if (!iswprint((wint_t) temp[n])) { result = FALSE; break; @@ -120,18 +123,18 @@ new_item(const char *name, const char *description) } else { - item = (ITEM *) calloc(1, sizeof(ITEM)); + item = typeCalloc(ITEM, 1); if (item) { *item = _nc_Default_Item; /* hope we have struct assignment */ - item->name.length = strlen(name); + item->name.length = (unsigned short)strlen(name); item->name.str = name; if (description && (*description != '\0') && Is_Printable_String(description)) { - item->description.length = strlen(description); + item->description.length = (unsigned short)strlen(description); item->description.str = description; } else @@ -160,7 +163,7 @@ new_item(const char *name, const char *description) NCURSES_EXPORT(int) free_item(ITEM * item) { - T((T_CALLED("free_item(%p)"), item)); + T((T_CALLED("free_item(%p)"), (void *)item)); if (!item) RETURN(E_BAD_ARGUMENT); @@ -193,12 +196,12 @@ free_item(ITEM * item) NCURSES_EXPORT(int) set_menu_mark(MENU * menu, const char *mark) { - unsigned l; + short l; - T((T_CALLED("set_menu_mark(%p,%s)"), menu, _nc_visbuf(mark))); + T((T_CALLED("set_menu_mark(%p,%s)"), (void *)menu, _nc_visbuf(mark))); if (mark && (*mark != '\0') && Is_Printable_String(mark)) - l = strlen(mark); + l = (short)strlen(mark); else l = 0; @@ -211,22 +214,22 @@ set_menu_mark(MENU * menu, const char *mark) { /* If the menu is already posted, the geometry is fixed. Then we can only accept a mark with exactly the same length */ - if (menu->marklen != (int)l) + if (menu->marklen != l) RETURN(E_BAD_ARGUMENT); } menu->marklen = l; if (l) { - menu->mark = (char *)malloc(l + 1); + menu->mark = strdup(mark); if (menu->mark) { - strcpy(menu->mark, mark); if (menu != &_nc_Default_Menu) - menu->status |= _MARK_ALLOCATED; + SetStatus(menu, _MARK_ALLOCATED); } else { menu->mark = old_mark; + menu->marklen = (short)((old_mark != 0) ? strlen(old_mark) : 0); RETURN(E_SYSTEM_ERROR); } } @@ -265,7 +268,7 @@ set_menu_mark(MENU * menu, const char *mark) NCURSES_EXPORT(const char *) menu_mark(const MENU * menu) { - T((T_CALLED("menu_mark(%p)"), menu)); + T((T_CALLED("menu_mark(%p)"), (const void *)menu)); returnPtr(Normalize_Menu(menu)->mark); }