diff options
author | Chad Elliott <elliottc@objectcomputing.com> | 2022-12-14 08:17:08 -0600 |
---|---|---|
committer | Chad Elliott <elliottc@objectcomputing.com> | 2022-12-14 08:17:08 -0600 |
commit | b7b81d09b6d0a15e384339fb1aa5c614d57435ae (patch) | |
tree | 478170ad749122adc7ffea8b395dc1adce9af41c | |
parent | 82e34020efffaadf8c1d0efc3a3ea1d7bc78cf24 (diff) | |
download | ATCD-b7b81d09b6d0a15e384339fb1aa5c614d57435ae.tar.gz |
Modified strenvdup() to avoid a second copy (via strdup) and silence a warning from gcc 11 about possibly returning a pointer to a local variable.
-rw-r--r-- | ACE/ace/OS_NS_stdlib.cpp | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/ACE/ace/OS_NS_stdlib.cpp b/ACE/ace/OS_NS_stdlib.cpp index e73808e9af7..612cfa5e8e3 100644 --- a/ACE/ace/OS_NS_stdlib.cpp +++ b/ACE/ace/OS_NS_stdlib.cpp @@ -136,20 +136,17 @@ ACE_OS::strenvdup (const ACE_TCHAR *str) size_t buf_len = ACE_OS::strlen (str) + 1; if (temp != 0) buf_len += ACE_OS::strlen (temp) - var_len; - ACE_TCHAR * buf_p = buf; - if (buf_len > ACE_DEFAULT_ARGV_BUFSIZ) - { - buf_p = + ACE_TCHAR * buf_p = #if defined (ACE_HAS_ALLOC_HOOKS) - (ACE_TCHAR *) ACE_Allocator::instance()->malloc (buf_len * sizeof (ACE_TCHAR)); + (ACE_TCHAR *) ACE_Allocator::instance()->malloc (buf_len * sizeof (ACE_TCHAR)); #else - (ACE_TCHAR *) ACE_OS::malloc (buf_len * sizeof (ACE_TCHAR)); + (ACE_TCHAR *) ACE_OS::malloc (buf_len * sizeof (ACE_TCHAR)); #endif /* ACE_HAS_ALLOC_HOOKS */ - if (buf_p == 0) - { - errno = ENOMEM; - return 0; - } + + if (buf_p == 0) + { + errno = ENOMEM; + return 0; } ACE_TCHAR * p = buf_p; size_t len = start - str; @@ -170,7 +167,7 @@ ACE_OS::strenvdup (const ACE_TCHAR *str) *p = ACE_TEXT ('\0'); } ACE_OS::strcpy (p, &start[var_len]); - return (buf_p == buf) ? ACE_OS::strdup (buf) : buf_p; + return buf_p; } else return ACE_OS::strdup (str); |