summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libc/string/__strerror.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/lib/libc/string/__strerror.c b/src/lib/libc/string/__strerror.c
index ccb430247e..87b47b68e4 100644
--- a/src/lib/libc/string/__strerror.c
+++ b/src/lib/libc/string/__strerror.c
@@ -28,7 +28,7 @@
28 */ 28 */
29 29
30#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
31static char *rcsid = "$OpenBSD: __strerror.c,v 1.11 2004/04/30 17:13:02 espie Exp $"; 31static char *rcsid = "$OpenBSD: __strerror.c,v 1.12 2004/05/01 10:52:59 espie Exp $";
32#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
33 33
34#ifdef NLS 34#ifdef NLS
@@ -59,11 +59,10 @@ __digits10(unsigned int num)
59 return i; 59 return i;
60} 60}
61 61
62static char * 62void
63__itoa(int num, char *buffer, size_t maxlen) 63__itoa(int num, char *buffer, size_t start, size_t end)
64{ 64{
65 char *p; 65 size_t pos;
66 size_t len;
67 unsigned int a; 66 unsigned int a;
68 int neg; 67 int neg;
69 68
@@ -76,22 +75,25 @@ __itoa(int num, char *buffer, size_t maxlen)
76 neg = 0; 75 neg = 0;
77 } 76 }
78 77
79 len = __digits10(a); 78 pos = start + __digits10(a);
80 if (neg) 79 if (neg)
81 len++; 80 pos++;
82 81
83 if (len >= maxlen) 82 if (pos < end)
84 return NULL; 83 buffer[pos] = '\0';
85 84 else
86 buffer[len--] = '\0'; 85 buffer[end-1] = '\0';
86 pos--;
87 do { 87 do {
88 buffer[len--] = (a % 10) + '0'; 88
89 if (pos < end)
90 buffer[pos] = (a % 10) + '0';
91 pos--;
89 a /= 10; 92 a /= 10;
90 } while (a != 0); 93 } while (a != 0);
91 if (neg) 94 if (neg)
92 *buffer = '-'; 95 if (pos < end)
93 96 buffer[pos] = '-';
94 return buffer;
95} 97}
96 98
97/* 99/*
@@ -125,8 +127,7 @@ __strerror(int num, char *buf)
125#else 127#else
126 len = strlcpy(buf, UPREFIX, NL_TEXTMAX); 128 len = strlcpy(buf, UPREFIX, NL_TEXTMAX);
127#endif 129#endif
128 if (len < NL_TEXTMAX) 130 __itoa(num, buf, len, NL_TEXTMAX);
129 __itoa(num, buf + len, NL_TEXTMAX - len);
130 errno = EINVAL; 131 errno = EINVAL;
131 } 132 }
132 133