[ipxe-devel] [PATCH 1/4] Fix strcmp()/strncmp() to return proper values

Aaron Young Aaron.Young at oracle.com
Wed Jan 9 19:35:39 UTC 2019


Fix strcmp() and strncmp() to return proper standard
positive/negative values for unequal strings. Current implementation is
backwards (i.e. the functions are returning negative when should be position
and vice-versa).

Currently all consumers of these functions only check the return
value for ==0 or !=0 and so we can safely change the
implementation without breaking things.

Signed-off-by: Aaron Young <Aaron.Young at oracle.com>
---
 src/core/string.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/core/string.c b/src/core/string.c
index 5a185e6..5bd9dae 100644
--- a/src/core/string.c
+++ b/src/core/string.c
@@ -173,7 +173,7 @@ int strncmp ( const char *first, const char *second, size_t max ) {
 	int diff;
 
 	for ( ; max-- ; first_bytes++, second_bytes++ ) {
-		diff = ( *second_bytes - *first_bytes );
+		diff = ( *first_bytes - *second_bytes );
 		if ( diff )
 			return diff;
 		if ( ! *first_bytes )
@@ -195,8 +195,8 @@ int strcasecmp ( const char *first, const char *second ) {
 	int diff;
 
 	for ( ; ; first_bytes++, second_bytes++ ) {
-		diff = ( toupper ( *second_bytes ) -
-			 toupper ( *first_bytes ) );
+		diff = ( toupper ( *first_bytes ) -
+			 toupper ( *second_bytes ) );
 		if ( diff )
 			return diff;
 		if ( ! *first_bytes )
-- 
1.8.3.1




More information about the ipxe-devel mailing list