diff options
author | Fred Hornsey <hornseyf@objectcomputing.com> | 2021-07-22 14:39:05 -0500 |
---|---|---|
committer | Fred Hornsey <hornseyf@objectcomputing.com> | 2021-07-22 14:39:05 -0500 |
commit | 2364cfbe655db819e94185d4ac96f8040228864a (patch) | |
tree | b130802f22c589c0faae04f1edf5a314fe811786 | |
parent | dd50c1191b8d87ca7e0d8bfa0b138a1950b6863c (diff) | |
download | ATCD-2364cfbe655db819e94185d4ac96f8040228864a.tar.gz |
Refactor DRV_cpp_putarg to Avoid ACE_TCHAR
-rw-r--r-- | TAO/TAO_IDL/driver/drv_preproc.cpp | 88 |
1 files changed, 43 insertions, 45 deletions
diff --git a/TAO/TAO_IDL/driver/drv_preproc.cpp b/TAO/TAO_IDL/driver/drv_preproc.cpp index 1244697bd83..19df12c6286 100644 --- a/TAO/TAO_IDL/driver/drv_preproc.cpp +++ b/TAO/TAO_IDL/driver/drv_preproc.cpp @@ -140,71 +140,69 @@ DRV_cpp_putarg (const char *str) throw Bailout (); } - const ACE_TCHAR *arg_to_add = nullptr; - - if (str && ACE_OS::strchr (str, ' ') && !ACE_OS::strchr (str, '"')) + char *replace = nullptr; + if (str) { - ACE_TCHAR *buf = nullptr; - ACE_NEW_NORETURN (buf, ACE_TCHAR[ACE_OS::strlen (str) + 3]); - if (buf) - { - buf[0] = ACE_TEXT ('"'); - ACE_OS::strcpy (buf + 1, ACE_TEXT_CHAR_TO_TCHAR (str)); - ACE_OS::strcat (buf, ACE_TEXT ("\"")); - arg_to_add = buf; - } - else + const char *const first_quote = ACE_OS::strchr (str, '"'); + bool allocate_error = false; + + if (ACE_OS::strchr (str, ' ') && !first_quote) { - idl_global->err()->misc_error ("DRV_cpp_putarg failed to allocate buffer!"); - throw Bailout (); + ACE_NEW_NORETURN (replace, char[ACE_OS::strlen (str) + 3]); + allocate_error = !replace; + if (replace) + { + replace[0] = '"'; + ACE_OS::strcpy (replace + 1, str); + ACE_OS::strcat (replace, "\""); + } } - } - else if (str) - { #ifdef ACE_WIN32 - // Escape Doublequotes on Windows - size_t quote_count = 0; - for (const char* quote = ACE_OS::strchr (str, '"'); quote; quote = ACE_OS::strchr (quote, '"')) + else if (first_quote) { - ++quote_count; - ++quote; - } - if (quote_count) - { - ACE_TCHAR *buf = nullptr; - ACE_NEW_NORETURN (buf, ACE_TCHAR[ACE_OS::strlen (str) + quote_count + 1]); - if (buf) + // Escape Doublequotes on Windows + + size_t quote_count = 0; + for (const char *quote = first_quote; quote; quote = ACE_OS::strchr (quote, '"')) + { + ++quote_count; + ++quote; + } + + ACE_NEW_NORETURN (replace, char[ACE_OS::strlen (str) + quote_count + 1]); + allocate_error = !replace; + if (replace) { - ACE_TCHAR *to = buf; - for (const char* from = str; *from; ++from) + char *to = replace; + for (const char *from = str; *from; ++from) { if (*from == '"') { - *to = ACE_TEXT ('\\'); + *to = '\\'; ++to; } *to = *from; ++to; } - *to = ACE_TEXT ('\0'); - arg_to_add = buf; - } - else - { - idl_global->err()->misc_error ("DRV_cpp_putarg failed to allocate buffer!"); - throw Bailout (); + *to = '\0'; } } - else +#endif + + if (allocate_error) { - arg_to_add = ACE::strnew (ACE_TEXT_CHAR_TO_TCHAR (str)); + idl_global->err()->misc_error ("DRV_cpp_putarg failed to allocate memory for argument!"); + throw Bailout (); } -#else - arg_to_add = ACE::strnew (ACE_TEXT_CHAR_TO_TCHAR (str)); -#endif } - DRV_arglist[DRV_argcount++] = arg_to_add; + DRV_arglist[DRV_argcount++] = ACE::strnew (ACE_TEXT_CHAR_TO_TCHAR (replace ? replace : str)); + + if (replace) + { + delete replace; + replace = nullptr; + } } // Expand the output argument with the given filename. |