Skip to content

Commit d4b9b5a

Browse files
committed
Use string instead
1 parent edb4038 commit d4b9b5a

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

src/common/cvt.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,17 +2369,18 @@ static void datetime_to_text(const dsc* from, dsc* to, Callbacks* cb)
23692369

23702370
if (!from->isTime())
23712371
{
2372-
// yyyy-mm-dd OR dd-MMM-yyyy + nul-termination
2373-
char dateStr[11 + 1];
2372+
string dateStr;
2373+
// yyyy-mm-dd OR dd-MMM-yyyy
2374+
dateStr.reserve(11);
23742375
if (from->dsc_dtype == dtype_sql_date || !version4)
23752376
{
2376-
snprintf(dateStr, sizeof(dateStr), "%4.4d-%2.2d-%2.2d",
2377+
dateStr.printf("%4.4d-%2.2d-%2.2d",
23772378
times.tm_year + 1900, times.tm_mon + 1, times.tm_mday);
23782379
}
23792380
else
23802381
{
23812382
// Prior to BLR version 5 timestamps were converted to text in the dd-MMM-yyyy format
2382-
snprintf(dateStr, sizeof(dateStr), "%2.2d-%.3s-%4.4d",
2383+
dateStr.printf("%2.2d-%.3s-%4.4d",
23832384
times.tm_mday,
23842385
FB_LONG_MONTHS_UPPER[times.tm_mon], times.tm_year + 1900);
23852386
}
@@ -2395,17 +2396,18 @@ static void datetime_to_text(const dsc* from, dsc* to, Callbacks* cb)
23952396

23962397
if (from->dsc_dtype != dtype_sql_date)
23972398
{
2398-
// hh:mm:ss.tttt + nul-termination
2399-
char timeStr[13 + 1];
2399+
string timeStr;
2400+
// hh:mm:ss.tttt
2401+
timeStr.reserve(13);
24002402
if (from->isTime() || !version4)
24012403
{
2402-
snprintf(timeStr, sizeof(timeStr), "%2.2d:%2.2d:%2.2d.%4.4d",
2404+
timeStr.printf("%2.2d:%2.2d:%2.2d.%4.4d",
24032405
times.tm_hour, times.tm_min, times.tm_sec, fractions);
24042406
}
24052407
else if (times.tm_hour || times.tm_min || times.tm_sec || fractions)
24062408
{
24072409
// Timestamp formating prior to BLR Version 5 is slightly different
2408-
snprintf(timeStr, sizeof(timeStr), " %d:%.2d:%.2d.%.4d",
2410+
timeStr.printf(" %d:%.2d:%.2d.%.4d",
24092411
times.tm_hour, times.tm_min, times.tm_sec, fractions);
24102412
}
24112413
temp.append(timeStr);

src/common/os/guid.h

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,34 +121,27 @@ class Guid
121121
memcpy(&m_data, buffer, SIZE);
122122
}
123123

124-
[[deprecated("use toString(char* buffer, size_t sz)")]]
125-
void toString(char* buffer) const
124+
template<typename T>
125+
void toString(T& str) const
126126
{
127-
sprintf(buffer, GUID_FORMAT,
127+
str.printf(GUID_FORMAT,
128128
m_data.Data1, m_data.Data2, m_data.Data3,
129129
m_data.Data4[0], m_data.Data4[1], m_data.Data4[2], m_data.Data4[3],
130130
m_data.Data4[4], m_data.Data4[5], m_data.Data4[6], m_data.Data4[7]);
131131
}
132132

133-
void toString(char* buffer, size_t sz) const
134-
{
135-
snprintf(buffer, sz, GUID_FORMAT,
136-
m_data.Data1, m_data.Data2, m_data.Data3,
137-
m_data.Data4[0], m_data.Data4[1], m_data.Data4[2], m_data.Data4[3],
138-
m_data.Data4[4], m_data.Data4[5], m_data.Data4[6], m_data.Data4[7]);
139-
}
140133

141134
Firebird::string toString() const
142135
{
143136
Firebird::string result;
144-
toString(result.getBuffer(GUID_BUFF_SIZE - 1), GUID_BUFF_SIZE);
137+
toString(result);
145138
return result;
146139
}
147140

148141
Firebird::PathName toPathName() const
149142
{
150143
Firebird::PathName result;
151-
toString(result.getBuffer(GUID_BUFF_SIZE - 1), GUID_BUFF_SIZE);
144+
toString(result);
152145
return result;
153146
}
154147

0 commit comments

Comments
 (0)