Skip to contentSkip to conversation

Replaced isprint() with a more multibyte friendly check

PATCH In review Daniel Gollub 2 participants 2 messages Nov 25, 2006 – Nov 26, 2006 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Replaced isprint() with a more multibyte friendly check

Hi,

there is a problem with multibyte chars when scanning with hcitool scan. This problem appears only when the device name was not stored in the adapters name list. I replace some isprint() with a more multibyte friendly check. This should avoid this problem and print also full names with multibyte chars included.

best regards,
Daniel

Index: tools/hciconfig.c
===================================================================
RCS file: /cvsroot/bluez/utils/tools/hciconfig.c,v retrieving revision 1.83

hciconfig.c +8 -4
diff -u -r1.83 hciconfig.c
@@ -473,9 +473,11 @@
 			exit(1);
 		}
 
-		for (i = 0; i < 248 && name[i]; i++)
-			if (!isprint(name[i]))
+		for (i = 0; i < 248 && name[i]; i++) {
+			if ((unsigned char) name[i] < 32 || name[i] == 127)
 				name[i] = '.';
+		}
+
 		name[248] = '\0';
 
 		print_dev_hdr(&di);
@@ -1002,9 +1004,11 @@
 				str = malloc(len);
 				if (str) {
 					snprintf(str, len, "%s", ptr);
-					for (i = 0; i < len - 1; i++)
-						if (!isprint(str[i]))
+					for (i = 0; i < len - 1; i++) {
+						if ((unsigned char) str[i] < 32 || str[i] == 127)
 							str[i] = '.';
+					}
+
 					printf("\t%s local name: \'%s\'\n",
 						type == 0x08 ? "Shortened" : "Complete", str);
 					free(str);

Index: tools/hcitool.c
===================================================================
RCS file: /cvsroot/bluez/utils/tools/hcitool.c,v
retrieving revision 1.91

hcitool.c +10 -6
diff -u -r1.91 hcitool.c
@@ -546,9 +546,11 @@
 					sizeof(name), name, 100000) < 0)
 				strcpy(name, "n/a");
 
-			for (n = 0; n < 248 && name[n]; n++)
-				if (!isprint(name[n]))
-					name[n] = '.';
+			for (n = 0; n < 248 && name[n]; n++) {
+				if ((unsigned char) name[i] < 32 || name[i] == 127)
+					name[i] = '.';
+			}
+
 			name[248] = '\0';
 
 			printf("\t%s\t%s\n", addr, name);
@@ -605,9 +607,11 @@
 				if (!nc)
 					strcpy(name, "n/a");
 			} else {
-				for (n = 0; n < 248 && name[n]; n++)
-					if (!isprint(name[n]))
-						name[n] = '.';
+				for (n = 0; n < 248 && name[n]; n++) {
+					if ((unsigned char) name[i] < 32 || name[i] == 127)
+						name[i] = '.';
+				}
+
 				name[248] = '\0';
 				nc = 0;
 			}

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#1 lore raw

Hi Daniel,

Quoted 5 lines

there is a problem with multibyte chars when scanning with hcitool scan. This problem appears only when the device name was not stored in the adapters name list. I replace some isprint() with a more multibyte friendly check. This should avoid this problem and print also full names with multibyte chars included.

the patch has been applied to the CVS. Thanks.

Regards

Marcel

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel