[PATCH V2] libx11:lcDefConv.c fix use before check

walter harms wharms at bfs.de
Sat Jun 7 03:03:17 PDT 2014


Hi Allen,
please try this one,
it is a simple diff between my current version and the current tar
Since i have no clue what my caused the problem, let alone how to
use git to fix it. i went back to a less sophisticated way.

Signed-off-by: Harms <wharms at bfs,de>


--- ./libX11-1.6.2/modules/lc/def/lcDefConv.c	2014-05-29 15:58:43.504106705 +0200
+++ ./libX11/modules/lc/def/lcDefConv.c	2014-06-07 11:03:06.936183532 +0200
@@ -149,14 +149,16 @@
     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,14 +183,16 @@
     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];
     int unconv = 0;

     if (from == NULL || *from == NULL)
-	return 0;
+      return 0;
+
+    src = (const wchar_t *) *from;

     while (*from_left && *to_left) {
 	(*from_left)--;
@@ -214,7 +218,7 @@
     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;
@@ -223,6 +227,7 @@

     if (from == NULL || *from == NULL)
 	return 0;
+    src = (const char *) *from;

     while (*from_left && *to_left) {
 	ch = *src++;
@@ -251,7 +256,7 @@
     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 +266,8 @@
     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 +297,7 @@
     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;
@@ -299,6 +306,7 @@

     if (from == NULL || *from == NULL)
 	return 0;
+    src = (const char *) *from;

     length = min(*from_left, *to_left);

@@ -336,7 +344,7 @@
     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 +354,8 @@
     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 +408,7 @@
     XPointer *args,
     int num_args)
 {
-    const char *src = (const char *) *from;
+    const char *src;
     char *dst = (char *) *to;
     CodeSet codeset;
     XlcCharSet charset;
@@ -410,6 +420,8 @@
     if (from == NULL || *from == NULL)
 	return 0;

+    src = (const char *) *from;
+
     if (num_args > 0) {
 	charset = (XlcCharSet) args[0];
 	if (charset == NULL)
@@ -467,8 +479,8 @@
     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 +491,8 @@
     if (from == NULL || *from == NULL)
 	return 0;

+    src= (const char *) *from;
+
     if (num_args > 0) {
 	charset = (XlcCharSet) args[0];
 	if (charset == NULL)
@@ -539,13 +553,15 @@
     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++;
@@ -563,10 +579,9 @@
 close_converter(
     XlcConv conv)
 {
-    if (conv->state)
-	Xfree(conv->state);

-    Xfree(conv);
+  Xfree(conv->state);
+  Xfree(conv);
 }

 static XlcConv


More information about the xorg-devel mailing list