From cd11bc699ac50af4f560ed5f2e5e7903de0898b8 Mon Sep 17 00:00:00 2001 From: Arnaud Versini Date: Fri, 9 May 2014 10:38:04 +0200 Subject: C string usage improvment Change-Id: I5c59f0d2d1b911ffa1ee251e0f1355d137616493 Signed-off-by: Stephan Bergmann --- cppuhelper/source/findsofficepath.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'cppuhelper') 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 ); -- cgit