svn commit: samba r17658 - in
branches/SAMBA_4_0/source/lib/replace: .
tridge at samba.org
tridge at samba.org
Mon Aug 21 07:41:17 GMT 2006
Author: tridge
Date: 2006-08-21 07:41:17 +0000 (Mon, 21 Aug 2006)
New Revision: 17658
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=17658
Log:
several replacement snprintf() fixes.
1) when running the testsuite, actually test against the system
sprintf(), not against ourselves (doh!)
2) fix the buffer termination to terminate buf2 as well
3) fix handling of %llu, and add a simple test
This fixes a bug with password expiry on solaris
Modified:
branches/SAMBA_4_0/source/lib/replace/snprintf.c
Changeset:
Modified: branches/SAMBA_4_0/source/lib/replace/snprintf.c
===================================================================
--- branches/SAMBA_4_0/source/lib/replace/snprintf.c 2006-08-21 06:57:17 UTC (rev 17657)
+++ branches/SAMBA_4_0/source/lib/replace/snprintf.c 2006-08-21 07:41:17 UTC (rev 17658)
@@ -247,7 +247,7 @@
static void fmtstr(char *buffer, size_t *currlen, size_t maxlen,
char *value, int flags, int min, int max);
static void fmtint(char *buffer, size_t *currlen, size_t maxlen,
- long value, int base, int min, int max, int flags);
+ LLONG value, int base, int min, int max, int flags);
static void fmtfp(char *buffer, size_t *currlen, size_t maxlen,
LDOUBLE fvalue, int min, int max, int flags);
static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c);
@@ -799,10 +799,10 @@
/* Have to handle DP_F_NUM (ie 0x and 0 alternates) */
static void fmtint(char *buffer, size_t *currlen, size_t maxlen,
- long value, int base, int min, int max, int flags)
+ LLONG value, int base, int min, int max, int flags)
{
int signvalue = 0;
- unsigned long uvalue;
+ unsigned LLONG uvalue;
char convert[20];
int place = 0;
int spadlen = 0; /* amount to space pad */
@@ -920,7 +920,7 @@
static double my_modf(double x0, double *iptr)
{
int i;
- long l;
+ LLONG l;
double x = x0;
double f = 1.0;
@@ -1299,7 +1299,7 @@
"%d",
NULL
};
- long int_nums[] = { -1, 134, 91340, 341, 0203, 0, 1234567890};
+ long int_nums[] = { -1, 134, 91340, 341, 0203, 1234567890, 0};
char *str_fmt[] = {
"%10.5s",
"%-10.5s",
@@ -1316,6 +1316,13 @@
NULL
};
char *str_vals[] = {"hello", "a", "", "a longer string", NULL};
+#ifdef HAVE_LONG_LONG
+ char *ll_fmt[] = {
+ "%llu",
+ NULL
+ };
+ LLONG ll_nums[] = { 134, 91340, 341, 0203, 1234567890, 128006186140000000LL, 0};
+#endif
int x, y;
int fail = 0;
int num = 0;
@@ -1327,9 +1334,9 @@
for (y = 0; fp_nums[y] != 0 ; y++) {
buf1[0] = buf2[0] = '\0';
l1 = snprintf(NULL, 0, fp_fmt[x], fp_nums[y]);
- l2 = snprintf(buf1, sizeof(buf1), fp_fmt[x], fp_nums[y]);
+ l2 = sprintf(buf1, fp_fmt[x], fp_nums[y]);
sprintf (buf2, fp_fmt[x], fp_nums[y]);
- buf1[1023] = buf1[1023] = '\0';
+ buf1[1023] = buf2[1023] = '\0';
if (strcmp (buf1, buf2) || (l1 != l2)) {
printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n",
fp_fmt[x], l1, buf1, l2, buf2);
@@ -1343,9 +1350,9 @@
for (y = 0; int_nums[y] != 0 ; y++) {
buf1[0] = buf2[0] = '\0';
l1 = snprintf(NULL, 0, int_fmt[x], int_nums[y]);
- l2 = snprintf(buf1, sizeof(buf1), int_fmt[x], int_nums[y]);
+ l2 = sprintf(buf1, int_fmt[x], int_nums[y]);
sprintf (buf2, int_fmt[x], int_nums[y]);
- buf1[1023] = buf1[1023] = '\0';
+ buf1[1023] = buf2[1023] = '\0';
if (strcmp (buf1, buf2) || (l1 != l2)) {
printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n",
int_fmt[x], l1, buf1, l2, buf2);
@@ -1359,9 +1366,9 @@
for (y = 0; str_vals[y] != 0 ; y++) {
buf1[0] = buf2[0] = '\0';
l1 = snprintf(NULL, 0, str_fmt[x], str_vals[y]);
- l2 = snprintf(buf1, sizeof(buf1), str_fmt[x], str_vals[y]);
+ l2 = sprintf(buf1, str_fmt[x], str_vals[y]);
sprintf (buf2, str_fmt[x], str_vals[y]);
- buf1[1023] = buf1[1023] = '\0';
+ buf1[1023] = buf2[1023] = '\0';
if (strcmp (buf1, buf2) || (l1 != l2)) {
printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n",
str_fmt[x], l1, buf1, l2, buf2);
@@ -1371,6 +1378,24 @@
}
}
+#ifdef HAVE_LONG_LONG
+ for (x = 0; ll_fmt[x] ; x++) {
+ for (y = 0; ll_nums[y] != 0 ; y++) {
+ buf1[0] = buf2[0] = '\0';
+ l1 = snprintf(NULL, 0, ll_fmt[x], ll_nums[y]);
+ l2 = sprintf(buf1, ll_fmt[x], ll_nums[y]);
+ sprintf (buf2, ll_fmt[x], ll_nums[y]);
+ buf1[1023] = buf2[1023] = '\0';
+ if (strcmp (buf1, buf2) || (l1 != l2)) {
+ printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n",
+ ll_fmt[x], l1, buf1, l2, buf2);
+ fail++;
+ }
+ num++;
+ }
+ }
+#endif
+
#define BUFSZ 2048
buf1[0] = buf2[0] = '\0';
@@ -1390,7 +1415,7 @@
buf1[0] = buf2[0] = '\0';
l1 = snprintf(buf1, sizeof(buf1), "%4$*1$d %2$s %3$*1$.*1$f", 3, "pos test", 12.3456, 9);
l2 = sprintf(buf2, "%4$*1$d %2$s %3$*1$.*1$f", 3, "pos test", 12.3456, 9);
- buf1[1023] = buf1[1023] = '\0';
+ buf1[1023] = buf2[1023] = '\0';
if (strcmp(buf1, buf2) || (l1 != l2)) {
printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n",
"%4$*1$d %2$s %3$*1$.*1$f", l1, buf1, l2, buf2);
@@ -1400,7 +1425,7 @@
buf1[0] = buf2[0] = '\0';
l1 = snprintf(buf1, sizeof(buf1), "%4$*4$d %2$s %3$*4$.*4$f", 3, "pos test", 12.3456, 9);
l2 = sprintf(buf2, "%4$*4$d %2$s %3$*4$.*4$f", 3, "pos test", 12.3456, 9);
- buf1[1023] = buf1[1023] = '\0';
+ buf1[1023] = buf2[1023] = '\0';
if (strcmp(buf1, buf2)) {
printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n",
"%4$*1$d %2$s %3$*1$.*1$f", l1, buf1, l2, buf2);
@@ -1410,7 +1435,7 @@
buf1[0] = buf2[0] = '\0';
l1 = snprintf(buf1, sizeof(buf1), "%lld", (LLONG)1234567890);
l2 = sprintf(buf2, "%lld", (LLONG)1234567890);
- buf1[1023] = buf1[1023] = '\0';
+ buf1[1023] = buf2[1023] = '\0';
if (strcmp(buf1, buf2)) {
printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n",
"%lld", l1, buf1, l2, buf2);
@@ -1420,7 +1445,7 @@
buf1[0] = buf2[0] = '\0';
l1 = snprintf(buf1, sizeof(buf1), "%Lf", (LDOUBLE)890.1234567890123);
l2 = sprintf(buf2, "%Lf", (LDOUBLE)890.1234567890123);
- buf1[1023] = buf1[1023] = '\0';
+ buf1[1023] = buf2[1023] = '\0';
if (strcmp(buf1, buf2)) {
printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n",
"%Lf", l1, buf1, l2, buf2);
More information about the samba-cvs
mailing list