From a8598e06240df4423aea79e659846409be6a75e9 Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Mon, 31 Jan 2011 14:02:13 +0200 Subject: lc/def/lcDefConv: Use Xcalloc to avoid use of uninitialized memory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed by zero'ing conv on allocation with Xcalloc. Then close_converter works properly. Using uninitialized value "conv->state" in call to function "close_converter" Reviewed-by: Alan Coopersmith Reviewed-by: Erkki Seppälä Signed-off-by: Ander Conselvan de Oliveira Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcDefConv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib/X11/lcDefConv.c') diff --git a/nx-X11/lib/X11/lcDefConv.c b/nx-X11/lib/X11/lcDefConv.c index 5860a79a5..12a48615e 100644 --- a/nx-X11/lib/X11/lcDefConv.c +++ b/nx-X11/lib/X11/lcDefConv.c @@ -577,7 +577,7 @@ create_conv( XlcConv conv; State state; - conv = (XlcConv) Xmalloc(sizeof(XlcConvRec)); + conv = (XlcConv) Xcalloc(1, sizeof(XlcConvRec)); if (conv == NULL) return (XlcConv) NULL; -- cgit v1.2.3 From c161df4fee61819a28089682963cc2e721ca22c8 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Aug 2013 23:51:08 -0700 Subject: Remove even more casts of return values from Xmalloc/Xrealloc Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcDefConv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib/X11/lcDefConv.c') diff --git a/nx-X11/lib/X11/lcDefConv.c b/nx-X11/lib/X11/lcDefConv.c index 12a48615e..a17d358a6 100644 --- a/nx-X11/lib/X11/lcDefConv.c +++ b/nx-X11/lib/X11/lcDefConv.c @@ -577,11 +577,11 @@ create_conv( XlcConv conv; State state; - conv = (XlcConv) Xcalloc(1, sizeof(XlcConvRec)); + conv = Xcalloc(1, sizeof(XlcConvRec)); if (conv == NULL) return (XlcConv) NULL; - state = (State) Xmalloc(sizeof(StateRec)); + state = Xmalloc(sizeof(StateRec)); if (state == NULL) { close_converter(conv); return (XlcConv) NULL; -- cgit v1.2.3 From 26256188b498e122e21ce0e05521dfc58f8b60a5 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 11 Aug 2013 00:07:33 -0700 Subject: Remove unnecessary casts of pointers to (char *) in calls to Xfree() Left one cast behind that is necessary to change from const char * to char * in nx-X11/lib/X11/lcCharSet.c. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcDefConv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib/X11/lcDefConv.c') diff --git a/nx-X11/lib/X11/lcDefConv.c b/nx-X11/lib/X11/lcDefConv.c index a17d358a6..3cd5c22c9 100644 --- a/nx-X11/lib/X11/lcDefConv.c +++ b/nx-X11/lib/X11/lcDefConv.c @@ -564,9 +564,9 @@ close_converter( XlcConv conv) { if (conv->state) - Xfree((char *) conv->state); + Xfree(conv->state); - Xfree((char *) conv); + Xfree(conv); } static XlcConv -- cgit v1.2.3 From 1ff6961231eda8929406b93fe3d70071cbba2469 Mon Sep 17 00:00:00 2001 From: walter harms Date: Fri, 6 Jun 2014 22:53:05 +0200 Subject: Remove more redundant null checks before Xfree() Signed-off-by: Harms Reviewed-by: Alan Coopersmith Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcDefConv.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'nx-X11/lib/X11/lcDefConv.c') diff --git a/nx-X11/lib/X11/lcDefConv.c b/nx-X11/lib/X11/lcDefConv.c index 3cd5c22c9..e1f02289b 100644 --- a/nx-X11/lib/X11/lcDefConv.c +++ b/nx-X11/lib/X11/lcDefConv.c @@ -563,9 +563,8 @@ static void close_converter( XlcConv conv) { - if (conv->state) - Xfree(conv->state); + Xfree(conv->state); Xfree(conv); } -- cgit v1.2.3 From aa7053b3eea7c98e155caf6ff6fd652f55b0547e Mon Sep 17 00:00:00 2001 From: walter harms Date: Sat, 7 Jun 2014 12:03:17 +0200 Subject: lcDefConv.c: fix use before check * Do not use variables before checked for NULL. * remove some superfluid spaces (Mark Kettenis) Signed-off-by: Harms Reviewed-by: Alan Coopersmith Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcDefConv.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'nx-X11/lib/X11/lcDefConv.c') diff --git a/nx-X11/lib/X11/lcDefConv.c b/nx-X11/lib/X11/lcDefConv.c index e1f02289b..51ad2f8e7 100644 --- a/nx-X11/lib/X11/lcDefConv.c +++ b/nx-X11/lib/X11/lcDefConv.c @@ -149,14 +149,16 @@ def_mbstowcs( XPointer *args, int num_args) { - const char *src = (const char *) *from; - wchar_t *dst = (wchar_t *) * to; + const char *src; + wchar_t *dst = (wchar_t *) *to; State state = (State) conv->state; int unconv = 0; if (from == NULL || *from == NULL) return 0; + src = (const char *) *from; + while (*from_left && *to_left) { (*from_left)--; if (state->MBtoWC (state, src++, dst)) { @@ -181,7 +183,7 @@ def_wcstombs( XPointer *args, int num_args) { - const wchar_t *src = (const wchar_t *) * from; + const wchar_t *src; char *dst = (char *) *to; State state = (State) conv->state; char ch[MB_LEN_MAX]; @@ -190,6 +192,8 @@ def_wcstombs( if (from == NULL || *from == NULL) return 0; + src = (const wchar_t *) *from; + while (*from_left && *to_left) { (*from_left)--; if (state->WCtoMB (state, *src++, ch)) { @@ -214,7 +218,7 @@ mbstostr( XPointer *args, int num_args) { - const char *src = (const char *) *from; + const char *src; char *dst = (char *) *to; CodeSet codeset; State state = (State) conv->state; @@ -224,6 +228,8 @@ mbstostr( if (from == NULL || *from == NULL) return 0; + src = (const char *) *from; + while (*from_left && *to_left) { ch = *src++; (*from_left)--; @@ -251,7 +257,7 @@ wcstostr( XPointer *args, int num_args) { - const wchar_t *src = (const wchar_t *) *from; + const wchar_t *src; char *dst = (char *) *to; CodeSet codeset; State state = (State) conv->state; @@ -261,6 +267,8 @@ wcstostr( if (from == NULL || *from == NULL) return 0; + src = (const wchar_t *) *from; + while (*from_left && *to_left) { (*from_left)--; if (state->WCtoMB (state, *src++, ch)) { @@ -290,7 +298,7 @@ mbstocs( XPointer *args, int num_args) { - const char *src = (const char *) *from; + const char *src; char *dst = (char *) *to; int length; State state = (State) conv->state; @@ -300,6 +308,7 @@ mbstocs( if (from == NULL || *from == NULL) return 0; + src = (const char *) *from; length = min(*from_left, *to_left); cur_side = *src & GR; @@ -336,7 +345,7 @@ wcstocs( XPointer *args, int num_args) { - const wchar_t *src = (const wchar_t *) * from; + const wchar_t *src; char *dst = (char *) *to; State state = (State) conv->state; char cur_side = 0, ch[MB_LEN_MAX]; @@ -346,6 +355,8 @@ wcstocs( if (from == NULL || *from == NULL) return 0; + src = (const wchar_t *) *from; + while (*from_left) { if ((found = state->WCtoMB (state, *src, ch))) break; @@ -398,7 +409,7 @@ cstombs( XPointer *args, int num_args) { - const char *src = (const char *) *from; + const char *src; char *dst = (char *) *to; CodeSet codeset; XlcCharSet charset; @@ -410,6 +421,8 @@ cstombs( if (from == NULL || *from == NULL) return 0; + src = (const char *) *from; + if (num_args > 0) { charset = (XlcCharSet) args[0]; if (charset == NULL) @@ -467,8 +480,8 @@ cstowcs( XPointer *args, int num_args) { - const char *src = (const char *) *from; - wchar_t *dst = (wchar_t *) * to; + const char *src; + wchar_t *dst = (wchar_t *) *to; CodeSet codeset; XlcCharSet charset; State state = (State) conv->state; @@ -479,6 +492,8 @@ cstowcs( if (from == NULL || *from == NULL) return 0; + src = (const char *) *from; + if (num_args > 0) { charset = (XlcCharSet) args[0]; if (charset == NULL) @@ -539,13 +554,14 @@ strtombs( XPointer *args, int num_args) { - const char *src = (const char *) *from; + const char *src; char *dst = (char *) *to; int length; if (from == NULL || *from == NULL) return 0; + src = (const char *) *from; length = min(*from_left, *to_left); while (length) { *dst++ = *src++; -- cgit v1.2.3