summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorArnaud Versini <arnaud.versini@gmail.com>2014-05-09 10:38:04 +0200
committerStephan Bergmann <sbergman@redhat.com>2014-05-20 09:47:54 +0200
commitcd11bc699ac50af4f560ed5f2e5e7903de0898b8 (patch)
tree2b5683460af2b171212bb766deb4cb7ee5858d4e /sal
parent498c314861f0913a5b31ee29efc38aad12c3a781 (diff)
C string usage improvment
Change-Id: I5c59f0d2d1b911ffa1ee251e0f1355d137616493 Signed-off-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/unx/socket.c8
-rw-r--r--sal/qa/osl/process/osl_Thread.cxx5
-rw-r--r--sal/qa/rtl/ostring/rtl_str.cxx14
3 files changed, 8 insertions, 19 deletions
diff --git a/sal/osl/unx/socket.c b/sal/osl/unx/socket.c
index e5b1d24b4a07..052ace914c1b 100644
--- a/sal/osl/unx/socket.c
+++ b/sal/osl/unx/socket.c
@@ -790,12 +790,10 @@ static oslHostAddr _osl_hostentToHostAddr (const struct hostent *he)
if (_osl_isFullQualifiedDomainName(he->h_name))
{
- cn= (sal_Char *)malloc(strlen (he->h_name) + 1);
+ cn= (sal_Char *)strdup(he->h_name);
OSL_ASSERT(cn);
if (cn == NULL)
return ((oslHostAddr)NULL);
-
- strcpy(cn, he->h_name);
}
else
{
@@ -889,13 +887,11 @@ oslHostAddr SAL_CALL osl_psz_createHostAddr (
if ((pszHostname == NULL) || (pAddr == NULL))
return ((oslHostAddr)NULL);
- cn = (sal_Char *)malloc(strlen (pszHostname) + 1);
+ cn = (sal_Char *) strdup(pszHostname);
OSL_ASSERT(cn);
if (cn == NULL)
return ((oslHostAddr)NULL);
- strcpy (cn, pszHostname);
-
pHostAddr= (oslHostAddr) malloc(sizeof(struct oslHostAddrImpl));
OSL_ASSERT(pHostAddr);
if (pHostAddr == NULL)
diff --git a/sal/qa/osl/process/osl_Thread.cxx b/sal/qa/osl/process/osl_Thread.cxx
index f5f43140e2eb..1122c2518c02 100644
--- a/sal/qa/osl/process/osl_Thread.cxx
+++ b/sal/qa/osl/process/osl_Thread.cxx
@@ -1919,10 +1919,7 @@ namespace osl_ThreadData
// at first, set the data a value
char* pc = new char[2];
char m_nData = 'm';
-// LLA: this is a copy functions only and really only for \0 terminated strings
-// m_nData is not a string, it's a character
-// strcpy(pc, &m_nData);
- memcpy(pc, &m_nData, 1);
+ pc[0] = m_nData;
pc[1] = '\0';
myThreadData.setData(pc);
diff --git a/sal/qa/rtl/ostring/rtl_str.cxx b/sal/qa/rtl/ostring/rtl_str.cxx
index 116191d353c4..759d30e9836a 100644
--- a/sal/qa/rtl/ostring/rtl_str.cxx
+++ b/sal/qa/rtl/ostring/rtl_str.cxx
@@ -711,10 +711,9 @@ namespace rtl_str
void trim_WithLength_001()
{
char const *pStr = " trim this";
- sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
+ sal_Char *pStr2 = (sal_Char*)strdup(pStr);
if (pStr2)
{
- strcpy(pStr2, pStr);
rtl_str_trim_WithLength( pStr2, 2 );
CPPUNIT_ASSERT_MESSAGE("string should be empty", strlen(pStr2) == 0);
@@ -725,10 +724,9 @@ namespace rtl_str
void trim_WithLength_002()
{
char const *pStr = "trim this";
- sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
+ sal_Char *pStr2 = (sal_Char*)strdup(pStr);
if (pStr2)
{
- strcpy(pStr2, pStr);
rtl_str_trim_WithLength( pStr2, 5 );
CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4);
@@ -739,7 +737,7 @@ namespace rtl_str
void trim_WithLength_003()
{
char const *pStr = " trim this";
- sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
+ sal_Char *pStr2 = (sal_Char*)strdup(pStr);
if (pStr2)
{
strcpy(pStr2, pStr);
@@ -753,10 +751,9 @@ namespace rtl_str
void trim_WithLength_004()
{
char const *pStr = "\r\n\t \n\r trim \n this";
- sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
+ sal_Char *pStr2 = (sal_Char*)strdup(pStr);
if (pStr2)
{
- strcpy(pStr2, pStr);
rtl_str_trim_WithLength( pStr2, 17 );
CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4);
@@ -767,10 +764,9 @@ namespace rtl_str
void trim_WithLength_005()
{
char const *pStr = "\r\n\t \n\r trim \t this \n\r\t\t ";
- sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
+ sal_Char *pStr2 = (sal_Char*)strdup(pStr);
if (pStr2)
{
- strcpy(pStr2, pStr);
rtl_str_trim_WithLength( pStr2, strlen(pStr2) );
CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 11);