Skip to contentSkip to conversation

FAT replace compare_sign with strncmp.

PATCH New Tom Rix 2 participants 2 messages May 20, 2009 – Jun 4, 2009 VFAT/FAT/msdos filesystem

lore
Share & tools
lore

Tom Rix

author
#0 lore raw

PATCH 1/1 FAT replace compare_sign with strncmp.

The static function compare_sign is only used to compare the fs_type string and does not do anything more than what strncmp does.

The addition of the trailing '\0' to fs_type, while legal, is not needed because the it is never printed out and strncmp does not depend on NULL terminated strings.

---
 fs/fat/fat.c |   36 +++---------------------------------
 1 files changed, 3 insertions(+), 33 deletions(-)
fs/fat/fat.c +3 -33
index 602edae..2445f1e 100644
@@ -140,28 +140,6 @@ dirdelim(char *str)
 	return -1;
 }
 
-
-/*
- * Match volume_info fs_type strings.
- * Return 0 on match, -1 otherwise.
- */
-static int
-compare_sign(char *str1, char *str2)
-{
-	char *end = str1+SIGNLEN;
-
-	while (str1 != end) {
-		if (*str1 != *str2) {
-			return -1;
-		}
-		str1++;
-		str2++;
-	}
-
-	return 0;
-}
-
-
 /*
  * Extract zero terminated short name from a directory entry.
  */
@@ -673,7 +651,6 @@ read_bootsectandvi(boot_sector *bs, volume_info *volinfo, int *fatsize)
 {
 	__u8 block[FS_BLOCK_SIZE];
 	volume_info *vistart;
-	char *fstype;
 
 	if (disk_read(0, 1, block) < 0) {
 		FAT_DPRINT("Error: reading block\n");
@@ -706,23 +683,16 @@ read_bootsectandvi(boot_sector *bs, volume_info *volinfo, int *fatsize)
 	}
 	memcpy(volinfo, vistart, sizeof(volume_info));
 
-	/*
-	 * Terminate fs_type string. Writing past the end of vistart
-	 * is ok - it's just the buffer.
-	 */
-	fstype = vistart->fs_type;
-	fstype[8] = '\0';
-
 	if (*fatsize == 32) {
-		if (compare_sign(FAT32_SIGN, vistart->fs_type) == 0) {
+		if (strncmp(FAT32_SIGN, vistart->fs_type, SIGNLEN) == 0) {
 			return 0;
 		}
 	} else {
-		if (compare_sign(FAT12_SIGN, vistart->fs_type) == 0) {
+		if (strncmp(FAT12_SIGN, vistart->fs_type, SIGNLEN) == 0) {
 			*fatsize = 12;
 			return 0;
 		}
-		if (compare_sign(FAT16_SIGN, vistart->fs_type) == 0) {
+		if (strncmp(FAT16_SIGN, vistart->fs_type, SIGNLEN) == 0) {
 			*fatsize = 16;
 			return 0;
 		}
Signature · 1 line
1.6.0.5
#1 lore raw

PATCH 1/1 FAT replace compare_sign with strncmp.

Dear Tom Rix,

Quoted 11 lines · In message <[email protected]> you wrote:

The static function compare_sign is only used to compare the fs_type string and does not do anything more than what strncmp does.

The addition of the trailing '\0' to fs_type, while legal, is not needed because the it is never printed out and strncmp does not depend on NULL terminated strings.

---
 fs/fat/fat.c |   36 +++---------------------------------
 1 files changed, 3 insertions(+), 33 deletions(-)

Applied to next, thanks.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
CONSUMER NOTICE:  Because  of  the  "Uncertainty  Principle,"  It  Is
Impossible  for  the  Consumer  to  Find  Out  at  the Same Time Both
Precisely Where This Product Is and How Fast It Is Moving.