Skip to content

Commit

Permalink
Merge pull request #1000 from simpsont-oci/avoid_unmanaged_strings_in…
Browse files Browse the repository at this point in the history
…_ace_env_helper

Avoid the use of unmanaged strings in ACE_Env_Helper
  • Loading branch information
jwillemsen authored Nov 21, 2019
2 parents 145d27a + ef30d34 commit 7f7cb13
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
7 changes: 4 additions & 3 deletions ACE/ace/XML_Utils/XML_Schema_Resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "XercesString.h"

#include "ace/Env_Value_T.h"
#include "ace/SString.h"

#include <iostream>

Expand Down Expand Up @@ -41,10 +42,10 @@ namespace XML
Environment_Resolver::add_path (const ACE_TCHAR *variable,
const ACE_TCHAR *relpath)
{
ACE_Env_Value <const ACE_TCHAR *> path_env (variable,
ACE_TEXT(""));
ACE_Env_Value <ACE_TString> path_env (variable,
ACE_TEXT(""));

XStr xpath (path_env);
XStr xpath (static_cast<ACE_TString>(path_env).c_str());
XStr xrelpath (relpath);

xpath.append (xrelpath);
Expand Down
2 changes: 1 addition & 1 deletion ACE/protocols/ace/INet/INet_Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace ACE
ACE_Env_Value<int> trace_env (ACE_TEXT("INET_TRACE_ENABLE"), 0);
trace = (trace_env != 0);

ACE_Env_Value<const ACE_TCHAR *> filename_env (ACE_TEXT("INET_LOG_FILE"), filename.c_str ());
ACE_Env_Value<ACE_TString> filename_env (ACE_TEXT("INET_LOG_FILE"), filename.c_str ());
filename = filename_env;

if (trace)
Expand Down
23 changes: 18 additions & 5 deletions ACE/tests/Env_Value_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "ace/OS_NS_string.h"
#include "ace/Process.h"
#include "ace/Env_Value_T.h"
#include "ace/SString.h"

#define TEST_THIS(type, varname, defval, expval) \
do { \
Expand Down Expand Up @@ -61,13 +62,25 @@ run_main (int, ACE_TCHAR* [])
TEST_THIS (short, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 0, -10);
TEST_THIS (unsigned short, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 0, (unsigned short) -10);

const ACE_TCHAR *defstr = ACE_TEXT ("Sarah Cleeland is Two!");
ACE_Env_Value<const ACE_TCHAR *> sval (ACE_TEXT ("This_Shouldnt_Be_Set_Hopefully"),
defstr);
if (ACE_OS::strcmp (sval, defstr) != 0)
const ACE_TCHAR* const defstr = ACE_TEXT ("Sarah Cleeland is Two!");

ACE_Env_Value<ACE_TString> sval1 (ACE_TEXT ("This_Shouldnt_Be_Set_Hopefully"),
defstr);
if (ACE_OS::strcmp (static_cast<ACE_TString>(sval1).c_str(), defstr) != 0) {
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Mismatch: %s should be %s\n"),
static_cast<ACE_TString>(sval1).c_str(), defstr));
}

const ACE_TString strval(ACE_TEXT("-10.2"));

ACE_Env_Value<ACE_TString> sval2 (ACE_TEXT ("TEST_VALUE_NEGATIVE"),
defstr);
if (ACE_OS::strcmp (static_cast<ACE_TString>(sval2).c_str(), strval.c_str()) != 0) {
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Mismatch: %s should be %s\n"),
(const ACE_TCHAR *)sval, defstr));
static_cast<ACE_TString>(sval2).c_str(), strval.c_str()));
}
ACE_END_TEST;
}
#endif // ACE_LACKS_PUTENV
Expand Down

0 comments on commit 7f7cb13

Please sign in to comment.