bio/b_print.c: switch to int64_t as "greatest-width integer type".

Originally there was dependency on BN configuration parameters, but
it stemmed from times when "long long" support was optional. Today
we require 64-bit support from compiler, and there is no reason to
have "greatest-width integer" depend on BN configuration.

Reviewed-by: Richard Levitte <levitte@openssl.org>
This commit is contained in:
Andy Polyakov 2017-03-30 21:44:55 +02:00
parent e6f648fd88
commit 15b337fa58

View file

@ -12,18 +12,8 @@
#include <ctype.h> #include <ctype.h>
#include "internal/numbers.h" #include "internal/numbers.h"
#include "internal/cryptlib.h" #include "internal/cryptlib.h"
#ifndef NO_SYS_TYPES_H
# include <sys/types.h>
#endif
#include <openssl/bn.h> /* To get BN_LLONG properly defined */
#include <openssl/bio.h> #include <openssl/bio.h>
#if defined(BN_LLONG) || defined(SIXTY_FOUR_BIT)
# ifndef HAVE_LONG_LONG
# define HAVE_LONG_LONG 1
# endif
#endif
/* /*
* Copyright Patrick Powell 1995 * Copyright Patrick Powell 1995
* This code is based on code written by Patrick Powell <papowell@astart.com> * This code is based on code written by Patrick Powell <papowell@astart.com>
@ -37,20 +27,10 @@
# define LDOUBLE double # define LDOUBLE double
#endif #endif
#ifdef HAVE_LONG_LONG
# if defined(_WIN32) && !defined(__GNUC__)
# define LLONG __int64
# else
# define LLONG long long
# endif
#else
# define LLONG long
#endif
static int fmtstr(char **, char **, size_t *, size_t *, static int fmtstr(char **, char **, size_t *, size_t *,
const char *, int, int, int); const char *, int, int, int);
static int fmtint(char **, char **, size_t *, size_t *, static int fmtint(char **, char **, size_t *, size_t *,
LLONG, int, int, int, int); int64_t, int, int, int, int);
static int fmtfp(char **, char **, size_t *, size_t *, static int fmtfp(char **, char **, size_t *, size_t *,
LDOUBLE, int, int, int, int); LDOUBLE, int, int, int, int);
static int doapr_outch(char **, char **, size_t *, size_t *, int); static int doapr_outch(char **, char **, size_t *, size_t *, int);
@ -107,7 +87,7 @@ _dopr(char **sbuffer,
size_t *retlen, int *truncated, const char *format, va_list args) size_t *retlen, int *truncated, const char *format, va_list args)
{ {
char ch; char ch;
LLONG value; int64_t value;
LDOUBLE fvalue; LDOUBLE fvalue;
char *strvalue; char *strvalue;
int min; int min;
@ -237,7 +217,7 @@ _dopr(char **sbuffer,
value = va_arg(args, long int); value = va_arg(args, long int);
break; break;
case DP_C_LLONG: case DP_C_LLONG:
value = va_arg(args, LLONG); value = va_arg(args, int64_t);
break; break;
case DP_C_SIZE: case DP_C_SIZE:
value = va_arg(args, ossl_ssize_t); value = va_arg(args, ossl_ssize_t);
@ -262,16 +242,16 @@ _dopr(char **sbuffer,
value = (unsigned short int)va_arg(args, unsigned int); value = (unsigned short int)va_arg(args, unsigned int);
break; break;
case DP_C_LONG: case DP_C_LONG:
value = (LLONG)va_arg(args, unsigned long int); value = va_arg(args, unsigned long int);
break; break;
case DP_C_LLONG: case DP_C_LLONG:
value = va_arg(args, unsigned LLONG); value = va_arg(args, uint64_t);
break; break;
case DP_C_SIZE: case DP_C_SIZE:
value = va_arg(args, size_t); value = va_arg(args, size_t);
break; break;
default: default:
value = (LLONG)va_arg(args, unsigned int); value = va_arg(args, unsigned int);
break; break;
} }
if (!fmtint(sbuffer, buffer, &currlen, maxlen, value, if (!fmtint(sbuffer, buffer, &currlen, maxlen, value,
@ -333,20 +313,8 @@ _dopr(char **sbuffer,
value, 16, min, max, flags | DP_F_NUM)) value, 16, min, max, flags | DP_F_NUM))
return 0; return 0;
break; break;
case 'n': /* XXX */ case 'n':
if (cflags == DP_C_SHORT) { {
short int *num;
num = va_arg(args, short int *);
*num = currlen;
} else if (cflags == DP_C_LONG) { /* XXX */
long int *num;
num = va_arg(args, long int *);
*num = (long int)currlen;
} else if (cflags == DP_C_LLONG) { /* XXX */
LLONG *num;
num = va_arg(args, LLONG *);
*num = (LLONG) currlen;
} else {
int *num; int *num;
num = va_arg(args, int *); num = va_arg(args, int *);
*num = currlen; *num = currlen;
@ -446,11 +414,11 @@ static int
fmtint(char **sbuffer, fmtint(char **sbuffer,
char **buffer, char **buffer,
size_t *currlen, size_t *currlen,
size_t *maxlen, LLONG value, int base, int min, int max, int flags) size_t *maxlen, int64_t value, int base, int min, int max, int flags)
{ {
int signvalue = 0; int signvalue = 0;
const char *prefix = ""; const char *prefix = "";
unsigned LLONG uvalue; uint64_t uvalue;
char convert[DECIMAL_SIZE(value) + 3]; char convert[DECIMAL_SIZE(value) + 3];
int place = 0; int place = 0;
int spadlen = 0; int spadlen = 0;
@ -463,7 +431,7 @@ fmtint(char **sbuffer,
if (!(flags & DP_F_UNSIGNED)) { if (!(flags & DP_F_UNSIGNED)) {
if (value < 0) { if (value < 0) {
signvalue = '-'; signvalue = '-';
uvalue = 0 - (unsigned LLONG)value; uvalue = 0 - (uint64_t)value;
} else if (flags & DP_F_PLUS) } else if (flags & DP_F_PLUS)
signvalue = '+'; signvalue = '+';
else if (flags & DP_F_SPACE) else if (flags & DP_F_SPACE)