[PATCH:libX11] Xcms file parsing should not require the impossible to succeed

Alan Coopersmith alan.coopersmith at oracle.com
Wed Oct 23 22:45:11 CEST 2013


The field2 helper function, to split lines from Xcms.txt files into
two tab delimited fields, contained a check:

    if ((*pBuf != '\n') || (*pBuf != '\0')) {
        return(XcmsFailure);

which would cause it to return failure unless *pBuf had a value that
was simultaneously equal to both \n & \0, and no one wants to live in
a world where that could ever be true.

This has gone unnoticed since 1991, until gcc -Wlogicalop came to our
rescue, and https://bugs.freedesktop.org/show_bug.cgi?id=70803 was filed.

Now that we see it, and cannot unsee it, we change it to use the
same logic as the check at other points in this function, to return
failure only if we hit \n or \0 before successfully finding two fields.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 src/xcms/cmsColNm.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/xcms/cmsColNm.c b/src/xcms/cmsColNm.c
index ecf19b3..ab6e4e8 100644
--- a/src/xcms/cmsColNm.c
+++ b/src/xcms/cmsColNm.c
@@ -314,7 +314,7 @@ field2(
 
     /* Find Field 1 */
     while (!isgraph(*pBuf)) {
-	if ((*pBuf != '\n') || (*pBuf != '\0')) {
+	if ((*pBuf == '\n') || (*pBuf == '\0')) {
 	    return(XcmsFailure);
 	}
 	if (isspace(*pBuf) || (*pBuf == delim)) {
-- 
1.7.9.2



More information about the xorg-devel mailing list