diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-05-28 16:43:24 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-05-28 16:43:24 +0000 |
commit | fa98a86f65cc2d71cbef5caa063f12c66233238c (patch) | |
tree | f9b5839fc1ee0a79eed479a787b746558f952f83 /src/backend/lib | |
parent | 7e72d07aa470e94849e30a740637ef37b50514e6 (diff) | |
download | postgresql-fa98a86f65cc2d71cbef5caa063f12c66233238c.tar.gz postgresql-fa98a86f65cc2d71cbef5caa063f12c66233238c.zip |
Tweak the code in a couple of places to try to deliver more user-friendly
error messages when a single COPY line is too long for us to handle. Per
example from Johann Spies.
Diffstat (limited to 'src/backend/lib')
-rw-r--r-- | src/backend/lib/stringinfo.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/backend/lib/stringinfo.c b/src/backend/lib/stringinfo.c index b0854ddc43b..a35f30b933b 100644 --- a/src/backend/lib/stringinfo.c +++ b/src/backend/lib/stringinfo.c @@ -9,7 +9,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/lib/stringinfo.c,v 1.45 2007/03/03 19:32:54 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/lib/stringinfo.c,v 1.46 2007/05/28 16:43:24 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -234,14 +234,17 @@ enlargeStringInfo(StringInfo str, int needed) int newlen; /* - * Guard against ridiculous "needed" values, which can occur if we're fed - * bogus data. Without this, we can get an overflow or infinite loop in - * the following. + * Guard against out-of-range "needed" values. Without this, we can get + * an overflow or infinite loop in the following. */ - if (needed < 0 || - ((Size) needed) >= (MaxAllocSize - (Size) str->len)) - elog(ERROR, "invalid string enlargement request size %d", - needed); + if (needed < 0) /* should not happen */ + elog(ERROR, "invalid string enlargement request size: %d", needed); + if (((Size) needed) >= (MaxAllocSize - (Size) str->len)) + ereport(ERROR, + (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("out of memory"), + errdetail("Cannot enlarge string buffer containing %d bytes by %d more bytes.", + str->len, needed))); needed += str->len + 1; /* total space required now */ |