* [PATCH 1/2] Various cleanups in kern/misc.c
@ 2005-06-29 14:30 Vincent Pelletier
2005-06-30 11:21 ` Rodrigo Steinmüller Wanderley
2005-07-02 17:35 ` [PATCH] use grub_size_t instead of int " Vincent Pelletier
0 siblings, 2 replies; 4+ messages in thread
From: Vincent Pelletier @ 2005-06-29 14:30 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 2065 bytes --]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi ! I did some grub hacking again yesterday, and here is the patch
resuming my changes. I only did a systematic read of misc.c to see if I
could find bugs & make improvements.
Don't check it in, as I haven't updated the places where grub_strchr and
grub_strrchr are used (so there are lots of warnings at build). Please
tell me if the patch is ok, and I'll make those updates (which will be
in [PATCH 2/2]).
I haven't read yet the 2 biggest functions : grub_vsprintf and
grub_split_cmdline, so there might be another patch if I find enough
courage to read them :).
2005-06-28 Vincent Pelletier <subdino2004@yahoo.fr>
* kern/misc.c
(grub_strncpy, grub_strncat, grub_strncmp, grub_strncasecmp):
Changed argument type from int to grub_size_t.
(grub_strcat, grub_strlen): Make "while" notation uniform.
(grub_strncat, grub_strncmp, grub_strncasecmp, grub_strlen):
Make maximum length check uniform.
(grub_strncasecmp): Make return value to also ignore case when we
reach the end of one string.
(grub_printf, grub_vprintf, grub_vsprintf, grub_sprintf): Changed
return type from int to grub_size_t.
(grub_strchr, grub_strrchr): Changed return type from char * to
const char *.
(grub_isupper, grub_islower, grub_toupper): New functions.
(grub_isalpha, grub_tolower): Use new functions.
(grub_itoa): Changed unsigned to unsigned int.
(grub_ftoa): intp can be negative, while fractp can't. Use a
float argument type.
* include/grub/mish.h
(grub_isupper, grub_islower, grub_toupper): New prototypes.
(grub_strncpy, grub_strncat, grub_strncmp,
grub_strncasecmp, grub_strchr, grub_strrchr, grub_printf,
grub_vprintf, grub_sprintf, grub_vsprintf): Updated prototypes to
match changes in kern/misc.c.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFCwrCcFEQoKRQyjtURArDNAJ9HPmv3nyMUBZkId1paaU8ASVQRCwCggW4J
TuWKLeApkSyYZv8hl0vAXKE=
=K7Co
-----END PGP SIGNATURE-----
[-- Attachment #2: misc_fix_1_of_2.diff --]
[-- Type: text/plain, Size: 8888 bytes --]
Index: kern/misc.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/misc.c,v
retrieving revision 1.20
diff -u -p -r1.20 misc.c
--- kern/misc.c 23 Jun 2005 23:13:57 -0000 1.20
+++ kern/misc.c 29 Jun 2005 13:59:30 -0000
@@ -63,7 +63,7 @@ grub_strcpy (char *dest, const char *src
}
char *
-grub_strncpy (char *dest, const char *src, int c)
+grub_strncpy (char *dest, const char *src, grub_size_t c)
{
char *p = dest;
@@ -91,8 +91,8 @@ grub_strcat (char *dest, const char *src
{
char *p = dest;
- while (*p)
- p++;
+ while (*p++)
+ ;
while ((*p++ = *src++) != '\0')
;
@@ -101,12 +101,12 @@ grub_strcat (char *dest, const char *src
}
char *
-grub_strncat (char *dest, const char *src, int c)
+grub_strncat (char *dest, const char *src, grub_size_t c)
{
char *p = dest;
- while (*p)
- p++;
+ while (*p++)
+ ;
while ((*p++ = *src++) != '\0' && --c)
;
@@ -115,11 +115,11 @@ grub_strncat (char *dest, const char *sr
return dest;
}
-int
+grub_size_t
grub_printf (const char *fmt, ...)
{
va_list ap;
- int ret;
+ grub_size_t ret;
va_start (ap, fmt);
ret = grub_vprintf (fmt, ap);
@@ -145,10 +145,10 @@ grub_real_dprintf(const char *file, cons
}
}
-int
+grub_size_t
grub_vprintf (const char *fmt, va_list args)
{
- int ret;
+ grub_size_t ret;
ret = grub_vsprintf (0, fmt, args);
grub_refresh ();
@@ -191,63 +191,57 @@ grub_strcmp (const char *s1, const char
}
int
-grub_strncmp (const char *s1, const char *s2, int c)
+grub_strncmp (const char *s1, const char *s2, grub_size_t c)
{
- int p = 1;
-
- while (*s1 && *s2 && p < c)
+ while (*s1 && *s2 && c--)
{
if (*s1 != *s2)
return (int) *s1 - (int) *s2;
s1++;
s2++;
- p++;
}
return (int) *s1 - (int) *s2;
}
int
-grub_strncasecmp (const char *s1, const char *s2, int c)
+grub_strncasecmp (const char *s1, const char *s2, grub_size_t c)
{
- int p = 1;
-
- while (grub_tolower (*s1) && grub_tolower (*s2) && p < c)
+ while (grub_tolower (*s1) && grub_tolower (*s2) && c--)
{
if (grub_tolower (*s1) != grub_tolower (*s2))
return (int) grub_tolower (*s1) - (int) grub_tolower (*s2);
s1++;
s2++;
- p++;
}
- return (int) *s1 - (int) *s2;
+ return (int) grub_tolower (*s1) - (int) grub_tolower (*s2);
}
-char *
+const char *
grub_strchr (const char *s, int c)
{
while (*s)
{
if (*s == c)
- return (char *) s;
+ return s;
s++;
}
return 0;
}
-char *
+const char *
grub_strrchr (const char *s, int c)
{
- char *p = 0;
+ const char *p = 0;
while (*s)
{
if (*s == c)
- p = (char *) s;
+ p = s;
s++;
}
@@ -310,9 +304,21 @@ grub_isprint (int c)
}
int
+grub_isupper (int c)
+{
+ return (c >= 'A' && c <= 'Z');
+}
+
+int
+grub_islower (int c)
+{
+ return (c >= 'a' && c <= 'z');
+}
+
+int
grub_isalpha (int c)
{
- return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
+ return grub_islower (c) || grub_isupper (c);
}
int
@@ -330,12 +336,21 @@ grub_isgraph (int c)
int
grub_tolower (int c)
{
- if (c >= 'A' && c <= 'Z')
+ if (grub_isupper (c))
return c - 'A' + 'a';
return c;
}
+int
+grub_toupper (int c)
+{
+ if (grub_islower (c))
+ return c - 'a' + 'A';
+
+ return c;
+}
+
unsigned long
grub_strtoul (const char *str, char **end, int base)
{
@@ -451,8 +466,8 @@ grub_strlen (const char *s)
{
const char *p = s;
- while (*p)
- p++;
+ while (*p++)
+ ;
return p - s;
}
@@ -475,21 +490,21 @@ grub_reverse (char *str)
}
static char *
-grub_itoa (char *str, int c, unsigned n)
+grub_itoa (char *str, int c, unsigned int n)
{
- unsigned base = (c == 'x') ? 16 : 10;
+ unsigned int base = (c == 'x') ? 16 : 10, d;
char *p;
if ((int) n < 0 && c == 'd')
{
- n = (unsigned) (-((int) n));
+ n = (unsigned int) (-((int) n));
*str++ = '-';
}
p = str;
do
{
- unsigned d = n % base;
+ d = n % base;
*p++ = (d > 9) ? d + 'a' - 10 : d + '0';
}
while (n /= base);
@@ -500,9 +515,9 @@ grub_itoa (char *str, int c, unsigned n)
}
static char *
-grub_ftoa (char *str, double f, int round)
+grub_ftoa (char *str, float f, int round)
{
- unsigned int intp;
+ int intp;
unsigned int fractp;
unsigned int power = 1;
int i;
@@ -513,15 +528,15 @@ grub_ftoa (char *str, double f, int roun
intp = f;
fractp = (f - (float) intp) * power;
- grub_sprintf (str, "%d.%d", intp, fractp);
+ grub_sprintf (str, "%d.%u", intp, fractp);
return str;
}
-int
+grub_size_t
grub_vsprintf (char *str, const char *fmt, va_list args)
{
char c;
- int count = 0;
+ grub_size_t count = 0;
auto void write_char (unsigned char ch);
auto void write_str (const char *s);
auto void write_fill (const char ch, int n);
@@ -729,11 +744,11 @@ grub_vsprintf (char *str, const char *fm
return count;
}
-int
+grub_size_t
grub_sprintf (char *str, const char *fmt, ...)
{
va_list ap;
- int ret;
+ grub_size_t ret;
va_start (ap, fmt);
ret = grub_vsprintf (str, fmt, ap);
Index: include/grub/misc.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/misc.h,v
retrieving revision 1.13
diff -u -p -r1.13 misc.h
--- include/grub/misc.h 9 May 2005 01:47:37 -0000 1.13
+++ include/grub/misc.h 29 Jun 2005 13:59:30 -0000
@@ -32,10 +32,10 @@
void *EXPORT_FUNC(grub_memmove) (void *dest, const void *src, grub_size_t n);
char *EXPORT_FUNC(grub_strcpy) (char *dest, const char *src);
-char *EXPORT_FUNC(grub_strncpy) (char *dest, const char *src, int c);
+char *EXPORT_FUNC(grub_strncpy) (char *dest, const char *src, grub_size_t c);
char *EXPORT_FUNC(grub_stpcpy) (char *dest, const char *src);
char *EXPORT_FUNC(grub_strcat) (char *dest, const char *src);
-char *EXPORT_FUNC(grub_strncat) (char *dest, const char *src, int c);
+char *EXPORT_FUNC(grub_strncat) (char *dest, const char *src, grub_size_t c);
/* Prototypes for aliases. */
void *EXPORT_FUNC(memmove) (void *dest, const void *src, grub_size_t n);
@@ -43,31 +43,34 @@ void *EXPORT_FUNC(memcpy) (void *dest, c
int EXPORT_FUNC(grub_memcmp) (const void *s1, const void *s2, grub_size_t n);
int EXPORT_FUNC(grub_strcmp) (const char *s1, const char *s2);
-int EXPORT_FUNC(grub_strncmp) (const char *s1, const char *s2, int c);
-int EXPORT_FUNC(grub_strncasecmp) (const char *s1, const char *s2, int c);
-char *EXPORT_FUNC(grub_strchr) (const char *s, int c);
-char *EXPORT_FUNC(grub_strrchr) (const char *s, int c);
+int EXPORT_FUNC(grub_strncmp) (const char *s1, const char *s2, grub_size_t c);
+int EXPORT_FUNC(grub_strncasecmp) (const char *s1, const char *s2, grub_size_t c);
+const char *EXPORT_FUNC(grub_strchr) (const char *s, int c);
+const char *EXPORT_FUNC(grub_strrchr) (const char *s, int c);
int EXPORT_FUNC(grub_strword) (const char *s, const char *w);
int EXPORT_FUNC(grub_iswordseparator) (int c);
int EXPORT_FUNC(grub_isspace) (int c);
int EXPORT_FUNC(grub_isprint) (int c);
+int EXPORT_FUNC(grub_isupper) (int c);
+int EXPORT_FUNC(grub_islower) (int c);
int EXPORT_FUNC(grub_isalpha) (int c);
int EXPORT_FUNC(grub_isgraph) (int c);
int EXPORT_FUNC(grub_isdigit) (int c);
int EXPORT_FUNC(grub_tolower) (int c);
+int EXPORT_FUNC(grub_toupper) (int c);
unsigned long EXPORT_FUNC(grub_strtoul) (const char *str, char **end, int base);
char *EXPORT_FUNC(grub_strdup) (const char *s);
char *EXPORT_FUNC(grub_strndup) (const char *s, grub_size_t n);
void *EXPORT_FUNC(grub_memset) (void *s, int c, grub_size_t n);
grub_size_t EXPORT_FUNC(grub_strlen) (const char *s);
-int EXPORT_FUNC(grub_printf) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
+grub_size_t EXPORT_FUNC(grub_printf) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
void EXPORT_FUNC(grub_real_dprintf) (const char *file,
const int line,
const char *condition,
const char *fmt, ...) __attribute__ ((format (printf, 4, 5)));
-int EXPORT_FUNC(grub_vprintf) (const char *fmt, va_list args);
-int EXPORT_FUNC(grub_sprintf) (char *str, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
-int EXPORT_FUNC(grub_vsprintf) (char *str, const char *fmt, va_list args);
+grub_size_t EXPORT_FUNC(grub_vprintf) (const char *fmt, va_list args);
+grub_size_t EXPORT_FUNC(grub_sprintf) (char *str, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
+grub_size_t EXPORT_FUNC(grub_vsprintf) (char *str, const char *fmt, va_list args);
void EXPORT_FUNC(grub_stop) (void) __attribute__ ((noreturn));
grub_uint8_t *EXPORT_FUNC(grub_utf16_to_utf8) (grub_uint8_t *dest,
grub_uint16_t *src,
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 1/2] Various cleanups in kern/misc.c
2005-06-29 14:30 [PATCH 1/2] Various cleanups in kern/misc.c Vincent Pelletier
@ 2005-06-30 11:21 ` Rodrigo Steinmüller Wanderley
2005-06-30 11:51 ` Rodrigo Steinmüller Wanderley
2005-07-02 17:35 ` [PATCH] use grub_size_t instead of int " Vincent Pelletier
1 sibling, 1 reply; 4+ messages in thread
From: Rodrigo Steinmüller Wanderley @ 2005-06-30 11:21 UTC (permalink / raw)
To: The development of GRUB 2
Hi Vicent,
Just one small comment here... I know its silly, but:
29/06 as 16:30: Vincent escreveu:
VP> static char *
VP> -grub_itoa (char *str, int c, unsigned n)
VP> +grub_itoa (char *str, int c, unsigned int n)
VP> {
VP> - unsigned base = (c == 'x') ? 16 : 10;
VP> + unsigned int base = (c == 'x') ? 16 : 10, d;
VP> char *p;
VP>
VP> if ((int) n < 0 && c == 'd')
VP> {
VP> - n = (unsigned) (-((int) n));
VP> + n = (unsigned int) (-((int) n));
VP> *str++ = '-';
VP> }
VP>
VP> p = str;
VP> do
VP> {
VP> - unsigned d = n % base;
VP> + d = n % base;
VP> *p++ = (d > 9) ? d + 'a' - 10 : d + '0';
VP> }
I think p is not necessary. Specially because we already used str to
walk through the string in the first if. What do you think?
VP> while (n /= base);
VP> @@ -500,9 +515,9 @@ grub_itoa (char *str, int c, unsigned n)
VP> }
--
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.1 (GNU/Linux)
mQGiBEKJ288RBAD43+VlxMx8V0dLbU+f7TsbhknjBYp2sRMP0a8IkHa8z4DgJTRd
XRMB0D05Hp5iE/1cA8t3e+g2J4kQhcj1JgUA6KSpYcj/cX6EKb6xhb/GAEQupaXz
7RYglwf4Sz9WJA3roSLtQuWcCOYR9lys+kifeTE2jnDLzDcuzwa2pEYJbwCg04jF
uyOmiBd09P1Bgq4VOQhYM78D/j0Iyj0QIstssnRPWcg4QL9l5c7Y8rLRH63qfGOi
fakmmY6C1JnW/wm4+2iUOc0/DbM+kKS5yXsiRFW7CDeqXLUEF1NIRvNaHkmfRmQf
shDI8NJCr0ULMbUde3b1U0LKgMRr7uVnVRFb2bPkEFh1mDEaxpy376+2Rpn8uHOu
GvqYBACJzY7EPP0fFQMMxeSyxHA7A/lxmC9/s1YtRgBHTCniYOQIZ+kwbFrU9XQv
ExvMeO2DvYAtDNyCgV/PaUm0yLxCAmxSVxQaAMRkOuMSKatyBggLpJVZKQ4WuayL
3xA+ws2+F2ozC/LHK9DodkGen35lP286QyPXOV2WciE4YciU3bQsUm9kcmlnbyBT
IFdhbmRlcmxleSA8cndhbmRlcmxleUBuYXRhbG5ldC5icj6IZAQTEQIAJAUCQonb
zwIbAwUJAeEzgAYLCQgHAwIDFQIDAxYCAQIeAQIXgAAKCRBuM/JKbknmQugDAKC6
ZfWsa8qone19+oppGBkrX028QACfUfLi9rSs/qxmE77b0P+xa2IrWN25Ag0EQonb
2xAIANBkeWLFcVSxSCsCQEH8HJ80VhQO18Sy80MpXebf9sj1gwUATZJ/OcxYYw46
ZrFwNk9raTRULprAcqR5ORKk3TNZ6ZnEl337PZZS5FnELwsHXTm+KVKF3bE2nnB5
/25SzPwkidsyk8Pe3HYM9/r4dwHNOXE3i0nYsweC/aUE8yg/3Ipweu9K1cj+XbSM
IpDydOmBpvVhIvv+VOIoevXxgm2hrD7LQ7jnfBaj/bV9GY/tJyl50nWgMM7csaAg
+4H1lG5/FvzNOgudmhzAdMk5lyTMLyRj6wiYkvckvBCXFaC04FgseylRj72NZilQ
xIstJWNomiATkC6uHYtOKExZ1xcAAwUIALTSG+l21w/W3L9iuEi8QK91n7LyHoO/
OJpYbj73sJWsui7qG63os8aR+KgbdbKNFGDwkyYfbfildYDd+TOkFWkbT64vq4Wv
t51Pl2dB0+0cnO/xqRnbxt4II7SBwg5t1u/MHahaULoTcTYslN+bW9FuB9I22ZiJ
pzFddDWjWApggNQIEapCd+XiuYnED6rV+n0GcmZxpb9Iz0mak7SPCZvN3QzPCI/6
k2YZlt92I/k4E2GU9NVM/1mXkTgqVgwOwlunPW6JYgcv/3n2Ly1eMNJQioWGRSnZ
wQyVx7FvBUqMGLrWHTw3+FQRDd6B6pQ2Y4uL0W4LskQrXm97hhW5NuKITwQYEQIA
DwUCQonb2wIbDAUJAeEzgAAKCRBuM/JKbknmQuXzAKDTa3d+h15/KHHupI6AMkNr
YKRP3ACggEq09XZBLGulCU2e6+/I0j4iN3U=
=JhUw
-----END PGP PUBLIC KEY BLOCK-----
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 1/2] Various cleanups in kern/misc.c
2005-06-30 11:21 ` Rodrigo Steinmüller Wanderley
@ 2005-06-30 11:51 ` Rodrigo Steinmüller Wanderley
0 siblings, 0 replies; 4+ messages in thread
From: Rodrigo Steinmüller Wanderley @ 2005-06-30 11:51 UTC (permalink / raw)
To: The development of GRUB 2
Sorry Vicent,
I was too lazy to look over the hole function and test it, I think there is more wrong in it.
--- misc.orig.c 2005-06-30 08:39:32.000000000 -0300
+++ misc.test.c 2005-06-30 08:44:31.000000000 -0300
static char *
grub_itoa (char *str, int c, unsigned n)
{
unsigned base = (c == 'x') ? 16 : 10, d;
char *p;
+
+ p = str;
if ((int) n < 0 && c == 'd')
{
n = (unsigned int) (-((int) n));
- *str++ = '-';
+ *p++ = '-';
}
- p = str;
do
{
d = n % base;
@@ -49,8 +50,8 @@
while (n /= base);
*p = 0;
- grub_reverse (str);
- return p;
+ grub_reverse ((*str == '-') ? str+1 : str);
+ return str;
}
int
What do you think?
Rodrigo
--
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.1 (GNU/Linux)
mQGiBEKJ288RBAD43+VlxMx8V0dLbU+f7TsbhknjBYp2sRMP0a8IkHa8z4DgJTRd
XRMB0D05Hp5iE/1cA8t3e+g2J4kQhcj1JgUA6KSpYcj/cX6EKb6xhb/GAEQupaXz
7RYglwf4Sz9WJA3roSLtQuWcCOYR9lys+kifeTE2jnDLzDcuzwa2pEYJbwCg04jF
uyOmiBd09P1Bgq4VOQhYM78D/j0Iyj0QIstssnRPWcg4QL9l5c7Y8rLRH63qfGOi
fakmmY6C1JnW/wm4+2iUOc0/DbM+kKS5yXsiRFW7CDeqXLUEF1NIRvNaHkmfRmQf
shDI8NJCr0ULMbUde3b1U0LKgMRr7uVnVRFb2bPkEFh1mDEaxpy376+2Rpn8uHOu
GvqYBACJzY7EPP0fFQMMxeSyxHA7A/lxmC9/s1YtRgBHTCniYOQIZ+kwbFrU9XQv
ExvMeO2DvYAtDNyCgV/PaUm0yLxCAmxSVxQaAMRkOuMSKatyBggLpJVZKQ4WuayL
3xA+ws2+F2ozC/LHK9DodkGen35lP286QyPXOV2WciE4YciU3bQsUm9kcmlnbyBT
IFdhbmRlcmxleSA8cndhbmRlcmxleUBuYXRhbG5ldC5icj6IZAQTEQIAJAUCQonb
zwIbAwUJAeEzgAYLCQgHAwIDFQIDAxYCAQIeAQIXgAAKCRBuM/JKbknmQugDAKC6
ZfWsa8qone19+oppGBkrX028QACfUfLi9rSs/qxmE77b0P+xa2IrWN25Ag0EQonb
2xAIANBkeWLFcVSxSCsCQEH8HJ80VhQO18Sy80MpXebf9sj1gwUATZJ/OcxYYw46
ZrFwNk9raTRULprAcqR5ORKk3TNZ6ZnEl337PZZS5FnELwsHXTm+KVKF3bE2nnB5
/25SzPwkidsyk8Pe3HYM9/r4dwHNOXE3i0nYsweC/aUE8yg/3Ipweu9K1cj+XbSM
IpDydOmBpvVhIvv+VOIoevXxgm2hrD7LQ7jnfBaj/bV9GY/tJyl50nWgMM7csaAg
+4H1lG5/FvzNOgudmhzAdMk5lyTMLyRj6wiYkvckvBCXFaC04FgseylRj72NZilQ
xIstJWNomiATkC6uHYtOKExZ1xcAAwUIALTSG+l21w/W3L9iuEi8QK91n7LyHoO/
OJpYbj73sJWsui7qG63os8aR+KgbdbKNFGDwkyYfbfildYDd+TOkFWkbT64vq4Wv
t51Pl2dB0+0cnO/xqRnbxt4II7SBwg5t1u/MHahaULoTcTYslN+bW9FuB9I22ZiJ
pzFddDWjWApggNQIEapCd+XiuYnED6rV+n0GcmZxpb9Iz0mak7SPCZvN3QzPCI/6
k2YZlt92I/k4E2GU9NVM/1mXkTgqVgwOwlunPW6JYgcv/3n2Ly1eMNJQioWGRSnZ
wQyVx7FvBUqMGLrWHTw3+FQRDd6B6pQ2Y4uL0W4LskQrXm97hhW5NuKITwQYEQIA
DwUCQonb2wIbDAUJAeEzgAAKCRBuM/JKbknmQuXzAKDTa3d+h15/KHHupI6AMkNr
YKRP3ACggEq09XZBLGulCU2e6+/I0j4iN3U=
=JhUw
-----END PGP PUBLIC KEY BLOCK-----
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] use grub_size_t instead of int in kern/misc.c
2005-06-29 14:30 [PATCH 1/2] Various cleanups in kern/misc.c Vincent Pelletier
2005-06-30 11:21 ` Rodrigo Steinmüller Wanderley
@ 2005-07-02 17:35 ` Vincent Pelletier
1 sibling, 0 replies; 4+ messages in thread
From: Vincent Pelletier @ 2005-07-02 17:35 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1: Type: text/plain, Size: 1047 bytes --]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
New version of the patch, made after a discussion with Okuji on irc.
The ftoa changes in previous version of this patch might be done later,
if someone confirms they are ok.
2005-07-02 Vincent Pelletier <subdino2004@yahoo.fr>
* kern/misc.c
(grub_strncpy, grub_strncat, grub_strncmp, grub_strncasecmp):
Changed argument type from int to grub_size_t.
(grub_printf, grub_vprintf, grub_vsprintf, grub_sprintf): Changed
return type from int to grub_size_t.
(grub_strncasecmp): Make return value to also ignore case when we
reach the end of one string.
* include/grub/mish.h
(grub_strncpy, grub_strncat, grub_strncmp,
grub_strncasecmp, grub_printf, grub_vprintf, grub_sprintf,
grub_vsprintf): Updated prototypes to match changes in
kern/misc.c.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFCxtBHFEQoKRQyjtURAsq3AKCTag1s0aqOATkdK54LYJ/K+ZQY2gCfeljo
Hiim/wgZjTV6Og9HTwMjItQ=
=UWpE
-----END PGP SIGNATURE-----
[-- Attachment #2: misc.diff --]
[-- Type: text/plain, Size: 5634 bytes --]
Index: kern/misc.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/misc.c,v
retrieving revision 1.20
diff -u -p -r1.20 misc.c
--- kern/misc.c 23 Jun 2005 23:13:57 -0000 1.20
+++ kern/misc.c 2 Jul 2005 17:29:05 -0000
@@ -63,7 +63,7 @@ grub_strcpy (char *dest, const char *src
}
char *
-grub_strncpy (char *dest, const char *src, int c)
+grub_strncpy (char *dest, const char *src, grub_size_t c)
{
char *p = dest;
@@ -101,7 +101,7 @@ grub_strcat (char *dest, const char *src
}
char *
-grub_strncat (char *dest, const char *src, int c)
+grub_strncat (char *dest, const char *src, grub_size_t c)
{
char *p = dest;
@@ -115,11 +115,11 @@ grub_strncat (char *dest, const char *sr
return dest;
}
-int
+grub_size_t
grub_printf (const char *fmt, ...)
{
va_list ap;
- int ret;
+ grub_size_t ret;
va_start (ap, fmt);
ret = grub_vprintf (fmt, ap);
@@ -145,10 +145,10 @@ grub_real_dprintf(const char *file, cons
}
}
-int
+grub_size_t
grub_vprintf (const char *fmt, va_list args)
{
- int ret;
+ grub_size_t ret;
ret = grub_vsprintf (0, fmt, args);
grub_refresh ();
@@ -191,9 +191,9 @@ grub_strcmp (const char *s1, const char
}
int
-grub_strncmp (const char *s1, const char *s2, int c)
+grub_strncmp (const char *s1, const char *s2, grub_size_t c)
{
- int p = 1;
+ grub_size_t p = 1;
while (*s1 && *s2 && p < c)
{
@@ -209,9 +209,9 @@ grub_strncmp (const char *s1, const char
}
int
-grub_strncasecmp (const char *s1, const char *s2, int c)
+grub_strncasecmp (const char *s1, const char *s2, grub_size_t c)
{
- int p = 1;
+ grub_size_t p = 1;
while (grub_tolower (*s1) && grub_tolower (*s2) && p < c)
{
@@ -223,7 +223,7 @@ grub_strncasecmp (const char *s1, const
p++;
}
- return (int) *s1 - (int) *s2;
+ return (int) grub_tolower (*s1) - (int) grub_tolower (*s2);
}
char *
@@ -517,11 +517,11 @@ grub_ftoa (char *str, double f, int roun
return str;
}
-int
+grub_size_t
grub_vsprintf (char *str, const char *fmt, va_list args)
{
char c;
- int count = 0;
+ grub_size_t count = 0;
auto void write_char (unsigned char ch);
auto void write_str (const char *s);
auto void write_fill (const char ch, int n);
@@ -729,11 +729,11 @@ grub_vsprintf (char *str, const char *fm
return count;
}
-int
+grub_size_t
grub_sprintf (char *str, const char *fmt, ...)
{
va_list ap;
- int ret;
+ grub_size_t ret;
va_start (ap, fmt);
ret = grub_vsprintf (str, fmt, ap);
Index: include/grub/misc.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/misc.h,v
retrieving revision 1.13
diff -u -p -r1.13 misc.h
--- include/grub/misc.h 9 May 2005 01:47:37 -0000 1.13
+++ include/grub/misc.h 2 Jul 2005 17:29:05 -0000
@@ -32,10 +32,10 @@
void *EXPORT_FUNC(grub_memmove) (void *dest, const void *src, grub_size_t n);
char *EXPORT_FUNC(grub_strcpy) (char *dest, const char *src);
-char *EXPORT_FUNC(grub_strncpy) (char *dest, const char *src, int c);
+char *EXPORT_FUNC(grub_strncpy) (char *dest, const char *src, grub_size_t c);
char *EXPORT_FUNC(grub_stpcpy) (char *dest, const char *src);
char *EXPORT_FUNC(grub_strcat) (char *dest, const char *src);
-char *EXPORT_FUNC(grub_strncat) (char *dest, const char *src, int c);
+char *EXPORT_FUNC(grub_strncat) (char *dest, const char *src, grub_size_t c);
/* Prototypes for aliases. */
void *EXPORT_FUNC(memmove) (void *dest, const void *src, grub_size_t n);
@@ -43,8 +43,8 @@ void *EXPORT_FUNC(memcpy) (void *dest, c
int EXPORT_FUNC(grub_memcmp) (const void *s1, const void *s2, grub_size_t n);
int EXPORT_FUNC(grub_strcmp) (const char *s1, const char *s2);
-int EXPORT_FUNC(grub_strncmp) (const char *s1, const char *s2, int c);
-int EXPORT_FUNC(grub_strncasecmp) (const char *s1, const char *s2, int c);
+int EXPORT_FUNC(grub_strncmp) (const char *s1, const char *s2, grub_size_t c);
+int EXPORT_FUNC(grub_strncasecmp) (const char *s1, const char *s2, grub_size_t c);
char *EXPORT_FUNC(grub_strchr) (const char *s, int c);
char *EXPORT_FUNC(grub_strrchr) (const char *s, int c);
int EXPORT_FUNC(grub_strword) (const char *s, const char *w);
@@ -60,14 +60,14 @@ char *EXPORT_FUNC(grub_strdup) (const ch
char *EXPORT_FUNC(grub_strndup) (const char *s, grub_size_t n);
void *EXPORT_FUNC(grub_memset) (void *s, int c, grub_size_t n);
grub_size_t EXPORT_FUNC(grub_strlen) (const char *s);
-int EXPORT_FUNC(grub_printf) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
+grub_size_t EXPORT_FUNC(grub_printf) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
void EXPORT_FUNC(grub_real_dprintf) (const char *file,
const int line,
const char *condition,
const char *fmt, ...) __attribute__ ((format (printf, 4, 5)));
-int EXPORT_FUNC(grub_vprintf) (const char *fmt, va_list args);
-int EXPORT_FUNC(grub_sprintf) (char *str, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
-int EXPORT_FUNC(grub_vsprintf) (char *str, const char *fmt, va_list args);
+grub_size_t EXPORT_FUNC(grub_vprintf) (const char *fmt, va_list args);
+grub_size_t EXPORT_FUNC(grub_sprintf) (char *str, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
+grub_size_t EXPORT_FUNC(grub_vsprintf) (char *str, const char *fmt, va_list args);
void EXPORT_FUNC(grub_stop) (void) __attribute__ ((noreturn));
grub_uint8_t *EXPORT_FUNC(grub_utf16_to_utf8) (grub_uint8_t *dest,
grub_uint16_t *src,
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-07-02 18:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-29 14:30 [PATCH 1/2] Various cleanups in kern/misc.c Vincent Pelletier
2005-06-30 11:21 ` Rodrigo Steinmüller Wanderley
2005-06-30 11:51 ` Rodrigo Steinmüller Wanderley
2005-07-02 17:35 ` [PATCH] use grub_size_t instead of int " Vincent Pelletier
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.