Merged in paimonen/nuttx/pullreq_libc_libnx_updates (pull request #757)

Pullreq libc libnx updates

* NuttX: make strerror() return 'Success' for 0

* NuttX: fix strrchr() so that it considers null terminator as part of string

    From strrchr(3) man page:
    "The terminating null byte is considered part of the string, so that if c
    is specified as '\0', these functions return a pointer to the terminator."

* NuttX: mm_free(): Add DEBUGASSERT()'s to catch memory corruption early.

    It's easier to find the source when asserts fail already when freeing
    an overflowed buffer, than if the corruption is only detected on next
    malloc().

* MM_FILL_ALLOCATIONS: Add debug option to fill all mallocs()

    This is helpful for detecting uninitialized variables,
    especially in C++ code. I seem to be forgetting to initialize
    member variables and then they just get random values..

* NuttX: nxtk_bitmapwindow: Fix warning message when bitmap is fully off-screen.

* nxfonts_getfont: Avoid unnecessary warnings for other whitespace chars also.

* NuttX: Fix kerning of 'I' in Sans17x22 font

    The I character was running together with some other
    characters, e.g. in sequence "IMI".

* NXMU: Revalidate window pointer for mouse events.

    NXMU caches the previous window pointer so that further mouse
    events can be sent to the same window. However, if the window
    is destroyed while mouse button is held down, the pointer may
    become invalid and cause a crash. This patch revalidates the
    pointer before using it.

Approved-by: GregoryN <gnutt@nuttx.org>
This commit is contained in:
Petteri Aimonen 2018-11-12 15:36:35 +00:00 committed by GregoryN
parent f337cc1380
commit fe0532c226
9 changed files with 82 additions and 10 deletions

View File

@ -58,6 +58,39 @@ static struct nxgl_point_s g_mrange;
static uint8_t g_mbutton;
static struct nxbe_window_s *g_mwnd;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nxmu_revalidate_g_mwnd
*
* Description:
* Check if the window pointed to by g_mwnd still exists. If it does,
* this function returns a pointer to it. Otherwise returns NULL.
*
****************************************************************************/
static struct nxbe_window_s *nxmu_revalidate_g_mwnd(struct nxbe_window_s *wnd)
{
if (!g_mwnd)
{
return NULL;
}
while (wnd)
{
if (wnd == g_mwnd)
{
return wnd;
}
wnd = wnd->below;
}
return NULL;
}
/****************************************************************************
* Public Functions
****************************************************************************/
@ -178,15 +211,24 @@ int nxmu_mousein(FAR struct nxfe_state_s *fe,
* started in.
*/
if (oldbuttons && g_mwnd && g_mwnd->cb->mousein)
if (oldbuttons)
{
struct nxclimsg_mousein_s outmsg;
outmsg.msgid = NX_CLIMSG_MOUSEIN;
outmsg.wnd = g_mwnd;
outmsg.buttons = g_mbutton;
nxgl_vectsubtract(&outmsg.pos, &g_mpos, &g_mwnd->bounds.pt1);
g_mwnd = nxmu_revalidate_g_mwnd(fe->be.topwnd);
if (g_mwnd && g_mwnd->cb->mousein)
{
struct nxclimsg_mousein_s outmsg;
outmsg.msgid = NX_CLIMSG_MOUSEIN;
outmsg.wnd = g_mwnd;
outmsg.buttons = g_mbutton;
nxgl_vectsubtract(&outmsg.pos, &g_mpos, &g_mwnd->bounds.pt1);
return nxmu_sendclientwindow(g_mwnd, &outmsg, sizeof(struct nxclimsg_mousein_s));
return nxmu_sendclientwindow(g_mwnd, &outmsg, sizeof(struct nxclimsg_mousein_s));
}
else
{
/* Ignore events until the button is released */
return OK;
}
}
/* Pick the window to receive the mouse event. Start with the top

View File

@ -76,6 +76,7 @@ struct errno_strmap_s
static const struct errno_strmap_s g_errnomap[] =
{
{ 0, "Success" },
{ EPERM, EPERM_STR },
{ ENOENT, ENOENT_STR },
{ ESRCH, ESRCH_STR },
@ -208,6 +209,7 @@ static const struct errno_strmap_s g_errnomap[] =
static const struct errno_strmap_s g_errnomap[] =
{
{ 0, "OK" },
{ EPERM, "EPERM" },
{ ENOENT, "ENOENT" },
{ ESRCH, "ESRCH" },

View File

@ -53,7 +53,7 @@ FAR char *strrchr(FAR const char *s, int c)
{
if (s)
{
const char *p = &s[strlen(s) - 1];
const char *p = &s[strlen(s)];
for (; p >= s; p--)
{
if (*p == c)

View File

@ -495,7 +495,7 @@ static inline FAR const struct nx_fontset_s *
* font.
*/
if (ch != ' ')
if (ch != ' ' && ch != '\t' && ch != '\n' && ch != '\r')
{
gwarn("WARNING: No bitmap for code %02x\n", ch);
}

View File

@ -226,7 +226,7 @@
#define NXFONT_BITMAP_72 {0x81, 0x81, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81, 0x81, 0x81}
/* I (73) */
#define NXFONT_METRICS_73 {1, 1, 11, 2, 6, 0}
#define NXFONT_METRICS_73 {1, 2, 11, 2, 6, 0}
#define NXFONT_BITMAP_73 {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80}
/* J (74) */

View File

@ -117,6 +117,12 @@ int nxtk_bitmapwindow(NXTKWINDOW hfwnd, FAR const struct nxgl_rect_s *dest,
nxtk_subwindowclip(fwnd, &clipdest, dest, &fwnd->fwrect);
/* Just return if completely outside screen */
if (nxgl_nullrect(&clipdest))
{
return OK;
}
/* Now, move the bitmap origin so that it is relative to the containing
* window, not the sub-window.
*

View File

@ -148,4 +148,11 @@ config MM_SHM
Build in support for the shared memory interfaces shmget(), shmat(),
shmctl(), and shmdt().
config MM_FILL_ALLOCATIONS
bool "Fill allocations with debug value"
default n
---help---
Fill all malloc() allocations with 0xAA. This helps
detecting uninitialized variable errors.
source "mm/iob/Kconfig"

View File

@ -81,11 +81,17 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem)
/* Map the memory chunk into a free node */
node = (FAR struct mm_freenode_s *)((FAR char *)mem - SIZEOF_MM_ALLOCNODE);
/* Sanity check against double-frees */
DEBUGASSERT(node->preceding & MM_ALLOC_BIT);
node->preceding &= ~MM_ALLOC_BIT;
/* Check if the following node is free and, if so, merge it */
next = (FAR struct mm_freenode_s *)((FAR char *)node + node->size);
DEBUGASSERT((next->preceding & ~MM_ALLOC_BIT) == node->size);
if ((next->preceding & MM_ALLOC_BIT) == 0)
{
FAR struct mm_allocnode_s *andbeyond;
@ -120,6 +126,7 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem)
*/
prev = (FAR struct mm_freenode_s *)((FAR char *)node - node->preceding);
DEBUGASSERT((node->preceding & ~MM_ALLOC_BIT) == prev->size);
if ((prev->preceding & MM_ALLOC_BIT) == 0)
{
/* Remove the node. There must be a predecessor, but there may

View File

@ -42,6 +42,7 @@
#include <assert.h>
#include <debug.h>
#include <string.h>
#include <nuttx/mm/mm.h>
@ -184,6 +185,13 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size)
mm_givesemaphore(heap);
#ifdef CONFIG_MM_FILL_ALLOCATIONS
if (ret)
{
memset(ret, 0xAA, alignsize - SIZEOF_MM_ALLOCNODE);
}
#endif
/* If CONFIG_DEBUG_MM is defined, then output the result of the allocation
* to the SYSLOG.
*/