Kunshchikov Vladimir wrote:
> Hello Alvaro,
> here goes v4 version: removed unused header.
> Compilation of this code snippet with -Wall -Wexter -std=c89 doesn't produce 
> any warnings.

Great, thanks.

+const char *
+get_cfp_error(cfp* fp)
+#ifdef HAVE_LIBZ
+       if(fp->compressedfp){
+               int errnum;
+               static const char fallback[] = "Zlib error";
+               const int maxlen = 255;
+               const char *errmsg = gzerror(fp->compressedfp, &errnum);
+               if(!errmsg || !memchr(errmsg, 0, maxlen))
+                       errmsg = fallback;
+               return errnum == Z_ERRNO ? strerror(errno) : errmsg;
+       }
+       return strerror(errno);

This "maxlen" business and the fallback error message are strange.  We
have roughly equivalent code in pg_basebackup.c, which has been working
since 2011 (commit 048d148fe631), and it looks like this:

#ifdef HAVE_LIBZ
static const char *
get_gz_error(gzFile gzf)
        int                     errnum;
        const char *errmsg;

        errmsg = gzerror(gzf, &errnum);
        if (errnum == Z_ERRNO)
                return strerror(errno);
                return errmsg;

Perhaps you can drop the memchr/fallback tricks and adopt the
pg_basebackup coding?  Or is there a specific reason to have the memchr

Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:

Reply via email to