Re: [HACKERS] [patch] pg_dump/pg_restore zerror() and strerror()mishap

Поиск
Список
Период
Сортировка
Искать
От
Alvaro Herrera
Тема
Re: [HACKERS] [patch] pg_dump/pg_restore zerror() and strerror()mishap
Дата
Msg-id
20170728162552.fhr5nfj5dvvxjhdh@alvherre.pgsql
Ответ на
Список
Дерево обсуждения
Re: [HACKERS] [patch] pg_dump/pg_restore zerror() and strerror()mishap Alvaro Herrera <alvherre@2ndquadrant.com>
Re: [HACKERS] [patch] pg_dump/pg_restore zerror() and strerror()mishap Kunshchikov Vladimir <Vladimir.Kunshchikov@infotecs.ru>
Re: [HACKERS] [patch] pg_dump/pg_restore zerror() and strerror()mishap Kunshchikov Vladimir <Vladimir.Kunshchikov@infotecs.ru>
Re: [HACKERS] [patch] pg_dump/pg_restore zerror() and strerror()mishap Alvaro Herrera <alvherre@2ndquadrant.com>
Re: [HACKERS] [patch] pg_dump/pg_restore zerror() and strerror()mishap Alvaro Herrera <alvherre@2ndquadrant.com>
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;
+	}#endif
+	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);else	return errmsg;
}
#endif

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

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


В списке pgsql-hackers по дате отправления
От: Jeff Janes
Дата:
FAQ