Skip to content

Commit 33d15a9

Browse files
fix: use memset if memset_s is not available (#107)
* fix: revert to memset if memset_s is not available * remove memset from tests
1 parent 0600769 commit 33d15a9

7 files changed

+24
-17
lines changed

psqlodbc.h

+10
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@
5050
#include <stdbool.h>
5151
#endif /* WIN32 */
5252

53+
/* For memset_s */
54+
#ifdef __STDC_LIB_EXT1__
55+
#define __STDC_WANT_LIB_EXT1__ 1
56+
#include <string.h>
57+
#endif /* __STDC_LIB_EXT1__ */
58+
5359
#ifdef __INCLUDE_POSTGRES_FE_H__ /* currently not defined */
5460
/*
5561
* Unfortunately #including postgres_fe.h causes various trobles.
@@ -134,7 +140,11 @@ void debug_memory_check(void);
134140
#ifdef WIN32
135141
#define pg_memset(dest, ch, count) SecureZeroMemory(dest, count)
136142
#else
143+
#ifdef __STDC_LIB_EXT1__
137144
#define pg_memset(dest, ch, count) memset_s(dest, count, ch, count)
145+
#else
146+
#define pg_memset(dest, ch, count) memset(dest, ch, count)
147+
#endif /* __STDC_LIB_EXT1__ */
138148
#endif /* WIN32 */
139149
#endif /* _MEMORY_DEBUG_ */
140150

test/src/bulkoperations-test.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ int main(int argc, char **argv)
5252
SQLLEN indColvalues1[3];
5353
SQLLEN indColvalues2[3];
5454

55-
pg_memset(bookmark, 0x7F, sizeof(bookmark));
56-
pg_memset(saved_bookmarks, 0xF7, sizeof(saved_bookmarks));
55+
memset(bookmark, 0x7F, sizeof(bookmark));
56+
memset(saved_bookmarks, 0xF7, sizeof(saved_bookmarks));
5757

5858
test_connect_ext("UpdatableCursors=1;Fetch=1");
5959

test/src/common.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919

2020
#ifdef WIN32
2121
#define snprintf _snprintf
22-
#define pg_memset(dest, ch, count) SecureZeroMemory(dest, count)
23-
#else
24-
#define pg_memset(dest, ch, count) memset_s(dest, count, ch, count)
25-
#endif /* WIN32 */
22+
#endif
2623

2724
extern SQLHENV env;
2825
extern SQLHDBC conn;

test/src/diagnostic-test.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int main(int argc, char **argv)
3636
/*
3737
* Test a very long error message.
3838
*/
39-
pg_memset(buf, 'x', sizeof(buf) - 10);
39+
memset(buf, 'x', sizeof(buf) - 10);
4040
sprintf(buf + sizeof(buf) - 10, "END");
4141
rc = SQLExecDirect(hstmt, (SQLCHAR *) buf, SQL_NTS);
4242
print_diag("SQLExecDirect", SQL_HANDLE_STMT, hstmt);

test/src/numeric-test.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ build_numeric_struct(SQL_NUMERIC_STRUCT *numericparam,
3333
int len;
3434

3535
/* parse the hex-encoded value */
36-
pg_memset(numericparam, 0, sizeof(SQL_NUMERIC_STRUCT));
36+
memset(numericparam, 0, sizeof(SQL_NUMERIC_STRUCT));
3737

3838
numericparam->sign = sign;
3939
numericparam->precision = precision;

test/src/odbc-escapes-test.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ static void escape_test(HSTMT hstmt)
142142
executeQuery(hstmt);
143143

144144
prepareQuery(hstmt, "{ ? = call length('foo') }");
145-
pg_memset(outbuf1, 0, sizeof(outbuf1));
145+
memset(outbuf1, 0, sizeof(outbuf1));
146146
bindOutParamString(hstmt, 1, NULL, outbuf1, sizeof(outbuf1) - 1, 0);
147147
executeQuery(hstmt);
148148
printf("OUT param: %s\n", outbuf1);
149149

150150
/* It's preferable to cast VARIADIC any fields */
151151
prepareQuery(hstmt, "{ ? = call concat(?::text, ?::text) }");
152-
pg_memset(outbuf1, 0, sizeof(outbuf1));
152+
memset(outbuf1, 0, sizeof(outbuf1));
153153
bindOutParamString(hstmt, 1, NULL, outbuf1, sizeof(outbuf1) - 1, 0);
154154
bindParamString(hstmt, 2, NULL, "foo");
155155
bindParamString(hstmt, 3, NULL, "bar");
@@ -172,22 +172,22 @@ static void escape_test(HSTMT hstmt)
172172

173173
/**** call procedure with out and i-o parameters ****/
174174
prepareQuery(hstmt, "{call a_b_c_d_e(?, ?, ?, ?, ?)}");
175-
pg_memset(outbuf1, 0, sizeof(outbuf1));
175+
memset(outbuf1, 0, sizeof(outbuf1));
176176
bindOutParamString(hstmt, 1, NULL, outbuf1, sizeof(outbuf1) - 1, 0);
177177
bindParamString(hstmt, 2, NULL, "2017-02-23 11:34:46");
178178
strcpy(outbuf3, "4");
179179
bindOutParamString(hstmt, 3, NULL, outbuf3, sizeof(outbuf3) - 1, 1);
180180
bindParamString(hstmt, 4, NULL, "3.4");
181-
pg_memset(outbuf5, 0, sizeof(outbuf5));
181+
memset(outbuf5, 0, sizeof(outbuf5));
182182
bindOutParamString(hstmt, 5, NULL, outbuf5, sizeof(outbuf5) - 1, 0);
183183
executeQuery(hstmt);
184184
printf("OUT params: %s : %s : %s\n", outbuf1, outbuf3, outbuf5);
185185

186186
/**** call procedure parameters by name (e,a,b,c,d) ****/
187187
prepareQuery(hstmt, "{call a_b_c_d_e(?, ?, ?, ?, ?)}");
188-
pg_memset(outbuf5, 0, sizeof(outbuf5));
188+
memset(outbuf5, 0, sizeof(outbuf5));
189189
bindOutParamString(hstmt, 1, "e", outbuf5, sizeof(outbuf5) - 1, 0);
190-
pg_memset(outbuf1, 0, sizeof(outbuf1));
190+
memset(outbuf1, 0, sizeof(outbuf1));
191191
bindOutParamString(hstmt, 2, "a", outbuf1, sizeof(outbuf1) - 1, 0);
192192
bindParamString(hstmt, 3, "b", "2017-02-23 11:34:46");
193193
strcpy(outbuf3, "4");
@@ -202,9 +202,9 @@ static void escape_test(HSTMT hstmt)
202202
strcpy(outbuf3, "4");
203203
bindOutParamString(hstmt, 2, "c", outbuf3, sizeof(outbuf3) - 1, 1);
204204
bindParamString(hstmt, 3, "d", "3.4");
205-
pg_memset(outbuf5, 0, sizeof(outbuf5));
205+
memset(outbuf5, 0, sizeof(outbuf5));
206206
bindOutParamString(hstmt, 4, "e", outbuf5, sizeof(outbuf5) - 1, 0);
207-
pg_memset(outbuf1, 0, sizeof(outbuf1));
207+
memset(outbuf1, 0, sizeof(outbuf1));
208208
bindOutParamString(hstmt, 5, "a", outbuf1, sizeof(outbuf1) - 1, 0);
209209
executeQuery(hstmt);
210210
printf("OUT params: %s : %s : %s\n", outbuf1, outbuf3, outbuf5);

test/src/result-conversions-test.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ test_conversion(const char *pgtype, const char *pgvalue, int sqltype, const char
476476
if (resultbuf == NULL)
477477
resultbuf = malloc(500);
478478

479-
pg_memset(resultbuf, 0xFF, 500);
479+
memset(resultbuf, 0xFF, 500);
480480

481481
fixed_len = get_sql_type_size(sqltype);
482482
if (fixed_len != -1)

0 commit comments

Comments
 (0)