Skip to content

Commit

Permalink
Fixed CORE-2756: substring from timestamp - unexpected result
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPeshkoff committed Jan 16, 2011
1 parent 130c32b commit e53f869
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 16 deletions.
46 changes: 38 additions & 8 deletions src/common/cvt.cpp
Expand Up @@ -1490,7 +1490,7 @@ void CVT_move_common(const dsc* from, dsc* to, Callbacks* cb)
{ // scope
USHORT strtype_unused;
UCHAR *ptr;
length = l = CVT_get_string_ptr(from, &strtype_unused, &ptr, NULL, 0, cb->err);
length = l = CVT_get_string_ptr_common(from, &strtype_unused, &ptr, NULL, 0, cb);
q = ptr;
} // end scope

Expand Down Expand Up @@ -1659,7 +1659,7 @@ void CVT_move_common(const dsc* from, dsc* to, Callbacks* cb)
{
USHORT strtype_unused;
UCHAR* ptr;
USHORT l = CVT_get_string_ptr(from, &strtype_unused, &ptr, NULL, 0, cb->err);
USHORT l = CVT_get_string_ptr_common(from, &strtype_unused, &ptr, NULL, 0, cb);

if (l == to->dsc_length)
{
Expand Down Expand Up @@ -2193,10 +2193,8 @@ SSHORT CVT_decompose(const char* string,
}


USHORT CVT_get_string_ptr(const dsc* desc,
USHORT* ttype,
UCHAR** address,
vary* temp, USHORT length, ErrorFunction err)
USHORT CVT_get_string_ptr_common(const dsc* desc, USHORT* ttype, UCHAR** address,
vary* temp, USHORT length, Callbacks* cb)
{
/**************************************
*
Expand All @@ -2223,7 +2221,7 @@ USHORT CVT_get_string_ptr(const dsc* desc,
fb_assert(desc != NULL);
fb_assert(ttype != NULL);
fb_assert(address != NULL);
fb_assert(err != NULL);
fb_assert(cb != NULL);
fb_assert((temp != NULL && length > 0) ||
desc->dsc_dtype == dtype_text ||
desc->dsc_dtype == dtype_cstring || desc->dsc_dtype == dtype_varying);
Expand Down Expand Up @@ -2266,7 +2264,7 @@ USHORT CVT_get_string_ptr(const dsc* desc,
temp_desc.dsc_address = (UCHAR *) temp;
INTL_ASSIGN_TTYPE(&temp_desc, ttype_ascii);
temp_desc.dsc_dtype = dtype_varying;
CVT_move(desc, &temp_desc, err);
CVT_move_common(desc, &temp_desc, cb);
*address = reinterpret_cast<UCHAR*>(temp->vary_string);
*ttype = INTL_TTYPE(&temp_desc);

Expand Down Expand Up @@ -2689,6 +2687,38 @@ namespace
} // namespace


USHORT CVT_get_string_ptr(const dsc* desc, USHORT* ttype, UCHAR** address,
vary* temp, USHORT length, ErrorFunction err)
{
/**************************************
*
* C V T _ g e t _ s t r i n g _ p t r
*
**************************************
*
* Functional description
* Get address and length of string, converting the value to
* string, if necessary. The caller must provide a sufficiently
* large temporary. The address of the resultant string is returned
* by reference. Get_string returns the length of the string (in bytes).
*
* The text-type of the string is returned in ttype.
*
* Note: If the descriptor is known to be a string type, the fourth
* argument (temp buffer) may be NULL.
*
* If input (desc) is already a string, the output pointers
* point to the data of the same text_type. If (desc) is not
* already a string, output pointers point to ttype_ascii.
*
**************************************/
fb_assert(err != NULL);

CommonCallbacks callbacks(err);
return CVT_get_string_ptr_common(desc, ttype, address, temp, length, &callbacks);
}


void CVT_move(const dsc* from, dsc* to, ErrorFunction err)
{
/**************************************
Expand Down
1 change: 1 addition & 0 deletions src/common/cvt.h
Expand Up @@ -75,6 +75,7 @@ void CVT_move_common(const dsc*, dsc*, Firebird::Callbacks*);
void CVT_move(const dsc*, dsc*, ErrorFunction);
SSHORT CVT_decompose(const char*, USHORT, SSHORT, SLONG*, ErrorFunction);
USHORT CVT_get_string_ptr(const dsc*, USHORT*, UCHAR**, vary*, USHORT, ErrorFunction);
USHORT CVT_get_string_ptr_common(const dsc*, USHORT*, UCHAR**, vary*, USHORT, Firebird::Callbacks*);
SINT64 CVT_get_int64(const dsc*, SSHORT, ErrorFunction);
SQUAD CVT_get_quad(const dsc*, SSHORT, ErrorFunction);

Expand Down
4 changes: 2 additions & 2 deletions src/jrd/SysFunction.cpp
Expand Up @@ -1376,7 +1376,7 @@ dsc* evlCharToUuid(Jrd::thread_db* tdbb, const SysFunction* function, Jrd::jrd_n

USHORT ttype;
UCHAR* data_temp;
const USHORT len = CVT_get_string_ptr(value, &ttype, &data_temp, NULL, 0, ERR_post);
const USHORT len = CVT_get_string_ptr(value, &ttype, &data_temp, NULL, 0);
const UCHAR* data = data_temp;

// validate the UUID
Expand Down Expand Up @@ -3271,7 +3271,7 @@ dsc* evlUuidToChar(Jrd::thread_db* tdbb, const SysFunction* function, Jrd::jrd_n

USHORT ttype;
UCHAR* data;
const USHORT len = CVT_get_string_ptr(value, &ttype, &data, NULL, 0, ERR_post);
const USHORT len = CVT_get_string_ptr(value, &ttype, &data, NULL, 0);

if (len != sizeof(FB_GUID))
{
Expand Down
6 changes: 3 additions & 3 deletions src/jrd/cvt2.cpp
Expand Up @@ -248,8 +248,8 @@ SSHORT CVT2_compare(const dsc* arg1, const dsc* arg2)
UCHAR* p1 = NULL;
UCHAR* p2 = NULL;
USHORT t1, t2; // unused later
USHORT length = CVT_get_string_ptr(arg1, &t1, &p1, NULL, 0, ERR_post);
USHORT length2 = CVT_get_string_ptr(arg2, &t2, &p2, NULL, 0, ERR_post);
USHORT length = CVT_get_string_ptr(arg1, &t1, &p1, NULL, 0);
USHORT length2 = CVT_get_string_ptr(arg2, &t2, &p2, NULL, 0);

int fill = length - length2;
const UCHAR pad = charset1 == ttype_binary || charset2 == ttype_binary ? '\0' : ' ';
Expand Down Expand Up @@ -420,7 +420,7 @@ SSHORT CVT2_compare(const dsc* arg1, const dsc* arg2)
{
UCHAR* p = NULL;
USHORT t; // unused later
USHORT length = CVT_get_string_ptr(arg2, &t, &p, NULL, 0, ERR_post);
USHORT length = CVT_get_string_ptr(arg2, &t, &p, NULL, 0);

USHORT l = MIN(arg1->dsc_length, length);
SSHORT rc = memcmp(arg1->dsc_address, p, l);
Expand Down
7 changes: 7 additions & 0 deletions src/jrd/cvt_proto.h
Expand Up @@ -70,4 +70,11 @@ inline void CVT_move(const dsc* from, dsc* to)
CVT_move_common(from, to, &Jrd::EngineCallbacks::instance);
}

inline USHORT CVT_get_string_ptr(const dsc* desc, USHORT* ttype, UCHAR** address,
vary* temp, USHORT length)
{
return CVT_get_string_ptr_common(desc, ttype, address, temp, length,
&Jrd::EngineCallbacks::instance);
}

#endif // JRD_CVT_PROTO_H
5 changes: 2 additions & 3 deletions src/jrd/mov.cpp
Expand Up @@ -203,8 +203,7 @@ void MOV_get_metadata_str(const dsc* desc, TEXT* buffer, USHORT buffer_length)
USHORT dummy_type;
UCHAR *ptr;

USHORT length = CVT_get_string_ptr(desc, &dummy_type, &ptr,
NULL, 0, ERR_post);
USHORT length = CVT_get_string_ptr(desc, &dummy_type, &ptr, NULL, 0);

#ifdef DEV_BUILD
if ((dummy_type != ttype_metadata) &&
Expand Down Expand Up @@ -276,7 +275,7 @@ int MOV_get_string_ptr(const dsc* desc,
*
**************************************/

return CVT_get_string_ptr(desc, ttype, address, temp, length, ERR_post);
return CVT_get_string_ptr(desc, ttype, address, temp, length);
}


Expand Down

0 comments on commit e53f869

Please sign in to comment.