diff options
-rw-r--r-- | cppuhelper/source/findsofficepath.c | 12 | ||||
-rw-r--r-- | desktop/unx/source/splashx.c | 2 | ||||
-rw-r--r-- | hwpfilter/source/grammar.cxx | 73 | ||||
-rw-r--r-- | rsc/source/rscpp/cpp3.c | 3 | ||||
-rw-r--r-- | sal/osl/unx/socket.c | 8 | ||||
-rw-r--r-- | sal/qa/osl/process/osl_Thread.cxx | 5 | ||||
-rw-r--r-- | sal/qa/rtl/ostring/rtl_str.cxx | 14 |
7 files changed, 53 insertions, 64 deletions
diff --git a/cppuhelper/source/findsofficepath.c b/cppuhelper/source/findsofficepath.c index 1bd73684787f..903b91bde303 100644 --- a/cppuhelper/source/findsofficepath.c +++ b/cppuhelper/source/findsofficepath.c @@ -135,8 +135,10 @@ static char* platformSpecific() env = getenv( PATHVARNAME ); if (env == NULL) return NULL; - str = (char*) malloc( strlen( env ) + 1 ); - strcpy( str, env ); + + str = strdup( env ); + if (str == NULL) + return NULL; /* get the tokens separated by ':' */ dir = strtok( str, PATHSEPARATOR ); @@ -145,6 +147,12 @@ static char* platformSpecific() { /* construct soffice file path */ file = (char*) malloc( strlen( dir ) + strlen( APPENDIX ) + 1 ); + if (file == NULL) + { + free(str); + return NULL; + } + strcpy( file, dir ); strcat( file, APPENDIX ); diff --git a/desktop/unx/source/splashx.c b/desktop/unx/source/splashx.c index 24b21526cf6f..288656c9b837 100644 --- a/desktop/unx/source/splashx.c +++ b/desktop/unx/source/splashx.c @@ -582,7 +582,7 @@ static void splash_load_image( struct splash* splash, rtl_uString* pUAppPath ) pLang = ustr_to_str (pLoc->Language); pCountry = ustr_to_str (pLoc->Country); - nLocSize = strlen (pLang->buffer) + strlen (pCountry->buffer) + 8; + nLocSize = strlen (pLang->buffer) + strlen (pCountry->buffer) + 3; pLocale = malloc (nLocSize); pLocale[0] = '-'; strcpy (pLocale + 1, pLang->buffer); diff --git a/hwpfilter/source/grammar.cxx b/hwpfilter/source/grammar.cxx index be4b591b01a6..fccd75f18409 100644 --- a/hwpfilter/source/grammar.cxx +++ b/hwpfilter/source/grammar.cxx @@ -44,13 +44,6 @@ Node *top=0L; int Node::count = 0; -#define allocValue(x,y) \ -x = (char *)malloc( strlen(y) +1 ); \ -strcpy(x,y) - -#define allocChar(x,y) \ -x = (char *)malloc(2); \ -sprintf(x,"%c",y) #ifdef PARSE_DEBUG #define debug printf #else @@ -836,55 +829,55 @@ yyreduce: switch (yyn) { case 1: -{ yyval.ptr = new Node(ID_IDENTIFIER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; break;} case 2: -{ yyval.ptr = new Node(ID_IDENTIFIER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; break;} case 3: -{ yyval.ptr = new Node(ID_IDENTIFIER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; break;} case 4: -{ yyval.ptr = new Node(ID_IDENTIFIER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; break;} case 5: -{ yyval.ptr = new Node(ID_IDENTIFIER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; break;} case 6: -{ yyval.ptr = new Node(ID_IDENTIFIER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; break;} case 7: -{ yyval.ptr = new Node(ID_IDENTIFIER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; break;} case 8: -{ yyval.ptr = new Node(ID_CHARACTER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_CHARACTER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; break;} case 9: -{ yyval.ptr = new Node(ID_OPERATOR); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_OPERATOR); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; break;} case 10: -{ yyval.ptr = new Node(ID_OPERATOR); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_OPERATOR); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; break;} case 11: -{ yyval.ptr = new Node(ID_IDENTIFIER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; break;} case 12: -{ yyval.ptr = new Node(ID_DELIMETER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_DELIMETER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; break;} case 13: -{ yyval.ptr = new Node(ID_DELIMETER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_DELIMETER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; break;} case 14: -{ yyval.ptr = new Node(ID_IDENTIFIER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; break;} case 15: -{ yyval.ptr = new Node(ID_CHARACTER); allocChar(yyval.ptr->value , '|'); debug("Identifier : '|'\n"); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_CHARACTER); yyval.ptr->value = strdup("|"); debug("Identifier : '|'\n"); nodelist.push_back(yyval.ptr); ; break;} case 16: -{ yyval.ptr = new Node(ID_NUMBER); allocValue(yyval.ptr->value , yyvsp[0].dval); debug("Number : %s\n",yyvsp[0].dval); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_NUMBER); yyval.ptr->value = strdup(yyvsp[0].dval); debug("Number : %s\n",yyvsp[0].dval); nodelist.push_back(yyval.ptr); ; break;} case 17: -{ yyval.ptr = new Node(ID_STRING); allocValue(yyval.ptr->value , yyvsp[0].str); debug("String : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_STRING); yyval.ptr->value = strdup(yyvsp[0].str); debug("String : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ; break;} case 18: { yyval.ptr = new Node(ID_PRIMARYEXPR); yyval.ptr->child = yyvsp[0].ptr; debug("PrimaryExpr\n"); nodelist.push_back(yyval.ptr); ; @@ -893,46 +886,46 @@ case 19: { yyval.ptr = new Node(ID_PRIMARYEXPR); yyval.ptr->child = yyvsp[-1].ptr; yyval.ptr->next = yyvsp[0].ptr; debug("PrimaryExpr : PrimaryExpr Identifier\n"); nodelist.push_back(yyval.ptr); ; break;} case 20: -{ yyval.ptr = new Node(ID_LEFT); allocChar(yyval.ptr->value , '('); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value = strdup("("); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ; break;} case 21: -{ yyval.ptr = new Node(ID_LEFT); allocChar(yyval.ptr->value , '['); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value = strdup("["); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ; break;} case 22: -{ yyval.ptr = new Node(ID_LEFT); allocChar(yyval.ptr->value , '{'); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value = strdup("{"); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ; break;} case 23: -{ yyval.ptr = new Node(ID_LEFT); allocChar(yyval.ptr->value , '<'); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value = strdup("<"); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ; break;} case 24: -{ yyval.ptr = new Node(ID_LEFT); allocChar(yyval.ptr->value , '|'); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value = strdup("|"); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ; break;} case 25: -{ yyval.ptr = new Node(ID_LEFT); allocValue(yyval.ptr->value , "||"); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value =strdup("||"); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ; break;} case 26: -{ yyval.ptr = new Node(ID_LEFT); allocValue(yyval.ptr->value , yyvsp[0].str); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value = strdup(yyvsp[0].str); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ; break;} case 27: -{ yyval.ptr = new Node(ID_RIGHT); allocChar(yyval.ptr->value , ')'); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup(")"); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ; break;} case 28: -{ yyval.ptr = new Node(ID_RIGHT); allocChar(yyval.ptr->value , ']'); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup("]"); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ; break;} case 29: -{ yyval.ptr = new Node(ID_RIGHT); allocChar(yyval.ptr->value , '}'); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup("}"); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ; break;} case 30: -{ yyval.ptr = new Node(ID_RIGHT); allocChar(yyval.ptr->value , '>'); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup(">"); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ; break;} case 31: -{ yyval.ptr = new Node(ID_RIGHT); allocChar(yyval.ptr->value , '|'); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup("|"); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ; break;} case 32: -{ yyval.ptr = new Node(ID_RIGHT); allocValue(yyval.ptr->value , "||"); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup("||"); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ; break;} case 33: -{ yyval.ptr = new Node(ID_RIGHT); allocValue(yyval.ptr->value , yyvsp[0].str); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup(yyvsp[0].str); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ; break;} case 34: { yyval.ptr = new Node(ID_FENCE); yyval.ptr->child=yyvsp[-2].ptr; yyvsp[-2].ptr->next=yyvsp[-1].ptr; yyvsp[-1].ptr->next=yyvsp[0].ptr; debug("Fence \n"); nodelist.push_back(yyval.ptr); ; @@ -971,13 +964,13 @@ case 45: { yyval.ptr = new Node(ID_OVER); yyval.ptr->child = yyvsp[-3].ptr; yyvsp[-3].ptr->next = yyvsp[-1].ptr; debug("OverExpr\n"); nodelist.push_back(yyval.ptr); ; break;} case 46: -{ yyval.ptr = new Node(ID_ACCENTEXPR); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Accent : %s\n", yyvsp[0].str); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_ACCENTEXPR); yyval.ptr->value = strdup(yyvsp[0].str); debug("Accent : %s\n", yyvsp[0].str); nodelist.push_back(yyval.ptr); ; break;} case 47: { yyval.ptr = new Node(ID_ACCENTEXPR); yyval.ptr->child=yyvsp[-1].ptr; yyvsp[-1].ptr->next = yyvsp[0].ptr; debug("AccentExpr \n"); nodelist.push_back(yyval.ptr); ; break;} case 48: -{ yyval.ptr = new Node(ID_DECORATIONEXPR); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Decoration : %s\n", yyvsp[0].str); nodelist.push_back(yyval.ptr); ; +{ yyval.ptr = new Node(ID_DECORATIONEXPR); yyval.ptr->value = strdup(yyvsp[0].str); debug("Decoration : %s\n", yyvsp[0].str); nodelist.push_back(yyval.ptr); ; break;} case 49: { yyval.ptr = new Node(ID_DECORATIONEXPR); yyval.ptr->child = yyvsp[-1].ptr; yyvsp[-1].ptr->next = yyvsp[0].ptr; debug("DecorationExpr \n"); nodelist.push_back(yyval.ptr); ; diff --git a/rsc/source/rscpp/cpp3.c b/rsc/source/rscpp/cpp3.c index b14f4f85a3b9..40635ed9f951 100644 --- a/rsc/source/rscpp/cpp3.c +++ b/rsc/source/rscpp/cpp3.c @@ -387,8 +387,7 @@ readoptions(char* filename, char*** pfargv) *poptbuff=EOS; if (strlen(optbuff)>0) { - pfa[fargc+1]=malloc(strlen(optbuff)+1); - strcpy(pfa[fargc+1],optbuff); + pfa[fargc+1]=strdup(optbuff); fargc++; pfa[fargc+1]=0; poptbuff=&optbuff[0]; 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); |