Skip to content

Commit

Permalink
1. initialize FILE* to NULL for sb_fopen
Browse files Browse the repository at this point in the history
2. remove the drop-in replacement for getenv and strerror.
   The solution will be more complicated and be offered later.
  • Loading branch information
sfc-gh-ext-simba-jz committed Oct 27, 2023
1 parent 75ef7b5 commit 7998227
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cpp/FileTransferAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,13 +617,13 @@ void Snowflake::Client::FileTransferAgent::compressSourceFile(
stagingFile += m_stmtPutGet->UTF8ToPlatformString(fileMetadata->destFileName);
std::string srcFileNamePlatform = m_stmtPutGet->UTF8ToPlatformString(fileMetadata->srcFileName);

FILE *sourceFile;
FILE *sourceFile = NULL;
sb_fopen(&sourceFile, fileMetadata->srcFileName.c_str(), "r");
if( !sourceFile ){
CXX_LOG_ERROR("Failed to open srcFileName %s. Errno: %d", fileMetadata->srcFileName.c_str(), errno);
throw SnowflakeTransferException(TransferError::FILE_OPEN_ERROR, srcFileNamePlatform.c_str(), -1);
}
FILE *destFile;
FILE *destFile = NULL;
sb_fopen(&destFile, stagingFile.c_str(), "w");
if ( !destFile) {
CXX_LOG_ERROR("Failed to open srcFileToUpload file %s. Errno: %d", stagingFile.c_str(), errno);
Expand Down
2 changes: 1 addition & 1 deletion cpp/lib/Authenticator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ namespace Client
void AuthenticatorJWT::loadPrivateKey(const std::string &privateKeyFile,
const std::string &passcode)
{
FILE *file;
FILE *file = NULL;
file = sb_fopen(&file, privateKeyFile.c_str(), "r");
if (file == nullptr)
{
Expand Down
12 changes: 4 additions & 8 deletions lib/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,10 @@ int STDCALL sf_setenv(const char *name, const char *value) {

char * STDCALL sf_getenv(const char *name) {
#ifdef _WIN32
static char buf[BUFSIZ];
size_t len = 0; // We don't use it, but Windows version doesn't like to pass NULL as lenght pointer. It crashes.
return getenv_s(&len, buf, sizeof(buf) - 1, name) ? NULL : buf;
#else
return getenv(name);
#endif
# else
return getenv(name);
# endif
}

int STDCALL sf_unsetenv(const char *name) {
Expand All @@ -295,9 +293,7 @@ int STDCALL sf_mkdir(const char *path) {
char* STDCALL sf_strerror(int in_errNumber)
{
#ifdef _WIN32
static char errStr[256];
strerror_s(errStr, sizeof(errStr), in_errNumber);
return errStr;
return strerror(in_errNumber);
#else
return strerror(in_errNumber);
#endif
Expand Down

0 comments on commit 7998227

Please sign in to comment.