All of lore.kernel.org
 help / color / mirror / Atom feed
* On grub_strchr implementation
@ 2009-11-01 18:54 BVK
  2009-11-01 21:58 ` Robert Millan
  0 siblings, 1 reply; 6+ messages in thread
From: BVK @ 2009-11-01 18:54 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 494 bytes --]

hi,


As per http://www.opengroup.org/onlinepubs/009695399/functions/strchr.html
strchr method should consider '\0' as part of the string, which means,
strchr should return '\0' character position when it is passed as the
character to look for.

I believe, grub_strchr is intended to mimic standard strchr semantics,
but its implementation doesn't confrom the above requirement.  Same
goes for grub_strrchr function too.  Attached is the patch to fix both
of these.


thanks,
-- 
bvk-chaitanya

[-- Attachment #2: fix-strchar.patch --]
[-- Type: application/octet-stream, Size: 861 bytes --]

=== modified file 'ChangeLog'
--- ChangeLog	2009-10-30 22:51:52 +0000
+++ ChangeLog	2009-11-01 18:39:54 +0000
@@ -1,3 +1,8 @@
+2009-11-02  BVK Chaitanya  <bvk.groups@gmail.com>
+
+	* kern/misc.c: Fixed grub_strchr and grub_strrchr functions for
+	'\0' case.
+
 2009-10-30  Robert Millan  <rmh.grub@aybabtu.com>
 
 	Fix build problem.

=== modified file 'kern/misc.c'
--- kern/misc.c	2009-08-24 19:40:40 +0000
+++ kern/misc.c	2009-11-01 18:49:08 +0000
@@ -223,12 +223,16 @@
 char *
 grub_strchr (const char *s, int c)
 {
-  while (*s)
+  if (! s)
+    return 0;
+
+  do
     {
       if (*s == c)
 	return (char *) s;
       s++;
     }
+  while (*s);
 
   return 0;
 }
@@ -238,12 +242,15 @@
 {
   char *p = 0;
 
-  while (*s)
+  if (! s)
+    return 0;
+
+  do
     {
       if (*s == c)
 	p = (char *) s;
-      s++;
     }
+  while (*s++);
 
   return p;
 }


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-11-02 14:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-01 18:54 On grub_strchr implementation BVK
2009-11-01 21:58 ` Robert Millan
2009-11-02  0:51   ` BVK
2009-11-02  5:55     ` BVK
2009-11-02 13:47     ` Robert Millan
2009-11-02 14:12       ` BVK

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.