Skip to content

Comments

fix: use memset if memset_s is not available#107

Merged
davecramer merged 2 commits intopostgresql-interfaces:mainfrom
faviansamatha:sfavian/memset-fix
Apr 15, 2025
Merged

fix: use memset if memset_s is not available#107
davecramer merged 2 commits intopostgresql-interfaces:mainfrom
faviansamatha:sfavian/memset-fix

Conversation

@faviansamatha
Copy link
Contributor

@faviansamatha faviansamatha commented Apr 11, 2025

Summary

A previous PR (#105) replaced the instances of memset with memset_s or SecureZeroMemory because there's a chance that compiler may remove these calls during optimization. However, this PR will break builds with compilers that do not have memset_s. memset_s was introduced in C11, but it is flagged as optional and many compilers like GCC do not implement this.

For the time being, this commit will re-introduce memset if memset_s is not implemented in the compiler by checking __STDC_LIB_EXT1__ and defining __STDC_WANT_LIB_EXT1__ before the needed imports. (reference: https://en.cppreference.com/w/c/string/byte/memset).

This commit also removes the changes in the unit test. memset should be safe in the unit tests. (previous implementaiton caused 2 unit tests to fail, (not ok 9 - result-conversions test output differs``not ok 40 - diagnostic test) because it used memset with a non-zero value.

Testing

Built on:

  • Mac M2
  • Windows
  • Linux Ubuntu 24

Ran regression test on Windows and tests had same results as mainline prior to 105

@davecramer davecramer merged commit 33d15a9 into postgresql-interfaces:main Apr 15, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants