Fix STR() truncating concatenated strings#4647
Draft
zheliu2 wants to merge 1 commit intobabelfish-for-postgresql:BABEL_5_X_DEVfrom
Draft
Fix STR() truncating concatenated strings#4647zheliu2 wants to merge 1 commit intobabelfish-for-postgresql:BABEL_5_X_DEVfrom
zheliu2 wants to merge 1 commit intobabelfish-for-postgresql:BABEL_5_X_DEVfrom
Conversation
) The STR() function was passing `length + 1` (including null terminator space) as the string size to tsql_varchar_input, causing the resulting varchar to include an extra byte. This extra byte caused any strings concatenated after STR() to be lost. Fix: use strlen(buf) to pass the actual string length instead of the buffer size.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4297
The
STR()function was passinglength + 1(buffer size including null terminator) as the string length totsql_varchar_input(), causing the resulting varchar to include an extra byte. This extra byte caused any strings concatenated afterSTR()to be silently lost.Root cause: In
contrib/babelfishpg_tsql/src/string.c, thefloat_str()function allocatedsize = length + 1bytes for the buffer (to accommodate the null terminator), but then passedsize(instead of the actual string length) toreturn_varchar_pointer().Fix: Changed
return_varchar_pointer(buf, size)toreturn_varchar_pointer(buf, strlen(buf))so the actual string length is used.Example:
Test plan
test/JDBC/input/functions/string_functions/str.sqltest/JDBC/expected/str.out