Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F151692853
D6511.id16733.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D6511.id16733.diff
View Options
Index: lib/libc/stdlib/a64l.c
===================================================================
--- lib/libc/stdlib/a64l.c
+++ lib/libc/stdlib/a64l.c
@@ -24,7 +24,7 @@
long
a64l(const char *s)
{
- long shift;
+ int32_t shift;
int digit, i, value;
value = 0;
Index: lib/libc/stdlib/l64a.c
===================================================================
--- lib/libc/stdlib/l64a.c
+++ lib/libc/stdlib/l64a.c
@@ -12,18 +12,13 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <stdint.h>
#include <stdlib.h>
-#define ADOT 46 /* ASCII '.' */
-#define ASLASH ADOT + 1 /* ASCII '/' */
-#define A0 48 /* ASCII '0' */
-#define AA 65 /* ASCII 'A' */
-#define Aa 97 /* ASCII 'a' */
-
char *
l64a(long value)
{
- static char buf[8];
+ static char buf[7];
(void)l64a_r(value, buf, sizeof(buf));
return (buf);
@@ -32,21 +27,20 @@
int
l64a_r(long value, char *buffer, int buflen)
{
- long v;
- int digit;
-
- v = value & (long)0xffffffff;
- for (; v != 0 && buflen > 1; buffer++, buflen--) {
- digit = v & 0x3f;
- if (digit < 2)
- *buffer = digit + ADOT;
- else if (digit < 12)
- *buffer = digit + A0 - 2;
- else if (digit < 38)
- *buffer = digit + AA - 12;
- else
- *buffer = digit + Aa - 38;
+ static const char chars[] =
+ "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+ uint32_t v;
+
+ v = value;
+ for (;;) {
+ if (buflen <= 0)
+ return (-1);
+ if (v == 0) {
+ *buffer = '\0';
+ return (0);
+ }
+ *buffer++ = chars[v & 0x3f];
+ --buflen;
v >>= 6;
}
- return (v == 0 ? 0 : -1);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 11, 1:44 AM (16 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31260950
Default Alt Text
D6511.id16733.diff (1 KB)
Attached To
Mode
D6511: Let l64a() properly null terminate its result.
Attached
Detach File
Event Timeline
Log In to Comment