Skip to content

Commit

Permalink
Emergency. blob::read(vector) was broken!
Browse files Browse the repository at this point in the history
This traditional `read()` method on `blob`, for compilers that don't
support `std::span`, did not read any data at all.  It just returned the
buffer you gave it.
  • Loading branch information
jtv committed May 8, 2021
1 parent 5c1b34f commit de66f00
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 21 deletions.
4 changes: 2 additions & 2 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
7.6.0
- More generic support for binary data in C++20.
7.5.2
- **Actual serious bug.** `blob::read(std::vector<...>)` was broken.
7.5.1
- Fixed some Visual Studio warnings.
- Missed a bit in working around MinGW's broken `<thread>`.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.6.0
7.5.2
2 changes: 1 addition & 1 deletion config/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ am__can_run_installinfo = \
esac
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
am__DIST_COMMON = $(srcdir)/Makefile.in compile config.guess \
config.sub depcomp install-sh ltmain.sh missing mkinstalldirs
config.sub install-sh ltmain.sh missing mkinstalldirs
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
Expand Down
22 changes: 11 additions & 11 deletions configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for libpqxx 7.6.0.
# Generated by GNU Autoconf 2.69 for libpqxx 7.5.2.
#
# Report bugs to <Jeroen T. Vermeulen>.
#
Expand Down Expand Up @@ -590,8 +590,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='libpqxx'
PACKAGE_TARNAME='libpqxx'
PACKAGE_VERSION='7.6.0'
PACKAGE_STRING='libpqxx 7.6.0'
PACKAGE_VERSION='7.5.2'
PACKAGE_STRING='libpqxx 7.5.2'
PACKAGE_BUGREPORT='Jeroen T. Vermeulen'
PACKAGE_URL=''

Expand Down Expand Up @@ -1360,7 +1360,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures libpqxx 7.6.0 to adapt to many kinds of systems.
\`configure' configures libpqxx 7.5.2 to adapt to many kinds of systems.

Usage: $0 [OPTION]... [VAR=VALUE]...

Expand Down Expand Up @@ -1431,7 +1431,7 @@ fi

if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of libpqxx 7.6.0:";;
short | recursive ) echo "Configuration of libpqxx 7.5.2:";;
esac
cat <<\_ACEOF

Expand Down Expand Up @@ -1557,7 +1557,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
libpqxx configure 7.6.0
libpqxx configure 7.5.2
generated by GNU Autoconf 2.69

Copyright (C) 2012 Free Software Foundation, Inc.
Expand Down Expand Up @@ -2047,7 +2047,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by libpqxx $as_me 7.6.0, which was
It was created by libpqxx $as_me 7.5.2, which was
generated by GNU Autoconf 2.69. Invocation command line was

$ $0 $@
Expand Down Expand Up @@ -4351,7 +4351,7 @@ fi

# Define the identity of the package.
PACKAGE='libpqxx'
VERSION='7.6.0'
VERSION='7.5.2'


cat >>confdefs.h <<_ACEOF
Expand Down Expand Up @@ -4573,7 +4573,7 @@ END
fi


PQXX_ABI=7.6
PQXX_ABI=7.5
PQXXVERSION=$PACKAGE_VERSION


Expand Down Expand Up @@ -19034,7 +19034,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by libpqxx $as_me 7.6.0, which was
This file was extended by libpqxx $as_me 7.5.2, which was
generated by GNU Autoconf 2.69. Invocation command line was

CONFIG_FILES = $CONFIG_FILES
Expand Down Expand Up @@ -19100,7 +19100,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
libpqxx config.status 7.6.0
libpqxx config.status 7.5.2
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"

Expand Down
5 changes: 3 additions & 2 deletions include/pqxx/blob.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ public:
* Returns the filled portion of @c buf. This may be empty.
*/
template<typename ALLOC>
std::basic_string_view<std::byte> read(std::vector<std::byte, ALLOC> buf)
std::basic_string_view<std::byte> read(std::vector<std::byte, ALLOC> &buf)
{
return std::basic_string_view<std::byte>{buf.data(), std::size(buf)};
return std::basic_string_view<std::byte>{
buf.data(), raw_read(buf.data(), std::size(buf))};
}

#endif // PQXX_HAVE_SPAN
Expand Down
2 changes: 1 addition & 1 deletion include/pqxx/doc/mainpage.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
libpqxx {#mainpage}
=======

@version 7.6.0
@version 7.5.2
@author Jeroen T. Vermeulen
@see http://pqxx.org
@see https://github.com/jtv/libpqxx
Expand Down
6 changes: 3 additions & 3 deletions include/pqxx/version.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
# include "pqxx/internal/compiler-internal-pre.hxx"

/// Full libpqxx version string.
# define PQXX_VERSION "7.6.0"
# define PQXX_VERSION "7.5.2"
/// Library ABI version.
# define PQXX_ABI "7.6"
# define PQXX_ABI "7.5"

/// Major version number.
# define PQXX_VERSION_MAJOR 7
/// Minor version number.
# define PQXX_VERSION_MINOR 6
# define PQXX_VERSION_MINOR 5

# define PQXX_VERSION_CHECK \
check_pqxx_version_##PQXX_VERSION_MAJOR##_##PQXX_VERSION_MINOR
Expand Down
15 changes: 15 additions & 0 deletions test/unit/test_blob.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,20 @@ void test_blob_read_span()
}


void test_blob_reads_vector()
{
char const content[]{"abcd"};
pqxx::connection conn;
pqxx::work tx{conn};
auto id{pqxx::blob::from_buf(tx, std::basic_string_view<std::byte>{reinterpret_cast<std::byte const *>(content), std::size(content)})};
std::vector<std::byte> buf;
buf.resize(10);
auto out{pqxx::blob::open_r(tx, id).read(buf)};
PQXX_CHECK_EQUAL(std::size(out), std::size(content), "Got wrong length back when reading as vector.");
PQXX_CHECK_EQUAL(out[0], std::byte{'a'}, "Got bad data when reading as vector.");
}


void test_blob_write_appends_at_insertion_point()
{
pqxx::connection conn;
Expand Down Expand Up @@ -535,6 +549,7 @@ PQXX_REGISTER_TEST(test_blob_remove_is_not_idempotent);
PQXX_REGISTER_TEST(test_blob_checks_open_mode);
PQXX_REGISTER_TEST(test_blob_supports_move);
PQXX_REGISTER_TEST(test_blob_read_reads_data);
PQXX_REGISTER_TEST(test_blob_reads_vector);
PQXX_REGISTER_TEST(test_blob_read_span);
PQXX_REGISTER_TEST(test_blob_write_appends_at_insertion_point);
PQXX_REGISTER_TEST(test_blob_resize_shortens_to_desired_length);
Expand Down

0 comments on commit de66f00

Please sign in to comment.