Conflicting declarations for b64_encode etc. on Solaris 11.4 Beta - Mailing list pgsql-bugs

From Rainer Orth
Subject Conflicting declarations for b64_encode etc. on Solaris 11.4 Beta
Date
Msg-id ydd372wk28h.fsf@CeBiTec.Uni-Bielefeld.DE
Whole thread Raw
Responses Re: Conflicting declarations for b64_encode etc. on Solaris 11.4 Beta
List pgsql-bugs
I just tried to compile postgresql 10.1 on Solaris 11.4 Beta with the
bundled GCC 5.5 and failed in two places:

/vol/src/postgresql/postgresql/postgresql-10.1/src/backend/utils/adt/encode.c:218:1: error: conflicting types for
‘b64_encode’
 b64_encode(const char *src, unsigned len, char *dst)
 ^
In file included from /vol/src/postgresql/postgresql/postgresql-10.1/src/include/c.h:83:0,
                 from /vol/src/postgresql/postgresql/postgresql-10.1/src/include/postgres.h:47,
                 from /vol/src/postgresql/postgresql/postgresql-10.1/src/backend/utils/adt/encode.c:14:
/usr/include/string.h:218:16: note: previous declaration of ‘b64_encode’ was here
 extern ssize_t b64_encode(char *_RESTRICT_KYWD outbuf, size_t outbufsz,
                ^
/vol/src/postgresql/postgresql/postgresql-10.1/src/backend/utils/adt/encode.c:265:1: error: conflicting types for
‘b64_decode’
 b64_decode(const char *src, unsigned len, char *dst)
 ^
In file included from /vol/src/postgresql/postgresql/postgresql-10.1/src/include/c.h:83:0,
                 from /vol/src/postgresql/postgresql/postgresql-10.1/src/include/postgres.h:47,
                 from /vol/src/postgresql/postgresql/postgresql-10.1/src/backend/utils/adt/encode.c:14:
/usr/include/string.h:221:16: note: previous declaration of ‘b64_decode’ was here
 extern ssize_t b64_decode(void *outbuf, size_t outbufsz, const char *inbuf,
                ^
make[4]: *** [<builtin>: encode.o] Error 1

Beside the static definition of b64_encode and b64_decode in
src/backend/utils/adt/encode.c, both functions are also declared in <string.h>:

#if defined(__EXTENSIONS__) ||                    \
    (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
extern ssize_t b64_encode(char *_RESTRICT_KYWD outbuf, size_t outbufsz,
    const void *_RESTRICT_KYWD inbuf, size_t inbufsz, const char *alpha,
    uint64_t flags);
extern ssize_t b64_decode(void *outbuf, size_t outbufsz, const char *inbuf,
    const char *alpha, uint64_t flags);

During the compilation, neither was __EXTENSIONS__ defined nor any macro
that would lead to _STRICT_STDC or _XOPEN_OR_POSIX being defined (any of
_STDC_VERSION/_XOPEN_SOURCE/_POSIX_SOURCE).

During make world, I ran into the same problem in contrib/pgcrypto/pgp-armor.c.

There are already a couple of instances of those functions with a pg_
prefix, obviously to avoid conflict with differing b64_{encode,decode}
declarations on other systems, but they don't match exactly:
e.g. src/include/common/base64.h has

extern int    pg_b64_encode(const char *src, int len, char *dst);
extern int    pg_b64_decode(const char *src, int len, char *dst);

while the encode.c and pgp-armor.c versions use an unsigned return value
and len argument.

However, since those two latter versions are static, adding a pg_ prefix
there, too, worked without conflict, allowed the compilation to finish
and make check to succeed.

    Rainer

--
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


===================================================================
RCS file: contrib/pgcrypto/RCS/pgp-armor.c,v
retrieving revision 1.1
diff -up -r1.1 contrib/pgcrypto/pgp-armor.c
--- contrib/pgcrypto/pgp-armor.c    2018/01/23 14:42:44    1.1
+++ contrib/pgcrypto/pgp-armor.c    2018/01/23 14:43:07
@@ -42,7 +42,7 @@ static const unsigned char _base64[] =
 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
 static int
-b64_encode(const uint8 *src, unsigned len, uint8 *dst)
+pg_b64_encode(const uint8 *src, unsigned len, uint8 *dst)
 {
     uint8       *p,
                *lend = dst + 76;
@@ -92,7 +92,7 @@ b64_encode(const uint8 *src, unsigned le
 
 /* probably should use lookup table */
 static int
-b64_decode(const uint8 *src, unsigned len, uint8 *dst)
+pg_b64_decode(const uint8 *src, unsigned len, uint8 *dst)
 {
     const uint8 *srcend = src + len,
                *s = src;
@@ -160,7 +160,7 @@ b64_decode(const uint8 *src, unsigned le
 }
 
 static unsigned
-b64_enc_len(unsigned srclen)
+pg_b64_enc_len(unsigned srclen)
 {
     /*
      * 3 bytes will be converted to 4, linefeed after 76 chars
@@ -169,7 +169,7 @@ b64_enc_len(unsigned srclen)
 }
 
 static unsigned
-b64_dec_len(unsigned srclen)
+pg_b64_dec_len(unsigned srclen)
 {
     return (srclen * 3) >> 2;
 }
@@ -218,11 +218,11 @@ pgp_armor_encode(const uint8 *src, unsig
         appendStringInfo(dst, "%s: %s\n", keys[n], values[n]);
     appendStringInfoChar(dst, '\n');
 
-    /* make sure we have enough room to b64_encode() */
-    b64len = b64_enc_len(len);
+    /* make sure we have enough room to pg_b64_encode() */
+    b64len = pg_b64_enc_len(len);
     enlargeStringInfo(dst, (int) b64len);
 
-    res = b64_encode(src, len, (uint8 *) dst->data + dst->len);
+    res = pg_b64_encode(src, len, (uint8 *) dst->data + dst->len);
     if (res > b64len)
         elog(FATAL, "overflow - encode estimate too small");
     dst->len += res;
@@ -358,14 +358,14 @@ pgp_armor_decode(const uint8 *src, int l
         goto out;
 
     /* decode crc */
-    if (b64_decode(p + 1, 4, buf) != 3)
+    if (pg_b64_decode(p + 1, 4, buf) != 3)
         goto out;
     crc = (((long) buf[0]) << 16) + (((long) buf[1]) << 8) + (long) buf[2];
 
     /* decode data */
-    blen = (int) b64_dec_len(len);
+    blen = (int) pg_b64_dec_len(len);
     enlargeStringInfo(dst, blen);
-    res = b64_decode(base64_start, base64_end - base64_start, (uint8 *) dst->data);
+    res = pg_b64_decode(base64_start, base64_end - base64_start, (uint8 *) dst->data);
     if (res > blen)
         elog(FATAL, "overflow - decode estimate too small");
     if (res >= 0)
===================================================================
RCS file: src/backend/utils/adt/RCS/encode.c,v
retrieving revision 1.1
diff -up -r1.1 src/backend/utils/adt/encode.c
--- src/backend/utils/adt/encode.c    2018/01/23 14:26:39    1.1
+++ src/backend/utils/adt/encode.c    2018/01/23 14:27:04
@@ -215,7 +215,7 @@ static const int8 b64lookup[128] = {
 };
 
 static unsigned
-b64_encode(const char *src, unsigned len, char *dst)
+pg_b64_encode(const char *src, unsigned len, char *dst)
 {
     char       *p,
                *lend = dst + 76;
@@ -262,7 +262,7 @@ b64_encode(const char *src, unsigned len
 }
 
 static unsigned
-b64_decode(const char *src, unsigned len, char *dst)
+pg_b64_decode(const char *src, unsigned len, char *dst)
 {
     const char *srcend = src + len,
                *s = src;
@@ -332,14 +332,14 @@ b64_decode(const char *src, unsigned len
 
 
 static unsigned
-b64_enc_len(const char *src, unsigned srclen)
+pg_b64_enc_len(const char *src, unsigned srclen)
 {
     /* 3 bytes will be converted to 4, linefeed after 76 chars */
     return (srclen + 2) * 4 / 3 + srclen / (76 * 3 / 4);
 }
 
 static unsigned
-b64_dec_len(const char *src, unsigned srclen)
+pg_b64_dec_len(const char *src, unsigned srclen)
 {
     return (srclen * 3) >> 2;
 }
@@ -532,7 +532,7 @@ static const struct
     {
         "base64",
         {
-            b64_enc_len, b64_dec_len, b64_encode, b64_decode
+            pg_b64_enc_len, pg_b64_dec_len, pg_b64_encode, pg_b64_decode
         }
     },
     {

pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #15025: PSQL CLI - inconsistency when both -d and -U supplies ausername
Next
From: Bruce Momjian
Date:
Subject: Re: [BUGS] BUG #14898: pg_upgrade documentation is misleading