hun#1999737 add some malloc checks

This commit is contained in:
Caolán McNamara 2010-03-04 13:08:22 +00:00
parent 7107dea0c0
commit e39ae52d7d
2 changed files with 15 additions and 12 deletions

View File

@ -1,5 +1,6 @@
2010-03-04 Caolán McNamara <cmc at OOo>: 2010-03-04 Caolán McNamara <cmc at OOo>:
- hun#1724558 tidy substring.c a little * hun#1724558 tidy substring.c a little
* hun#1999737 add some malloc checks
2010-02-23 László Németh <nemeth at OOo>: 2010-02-23 László Németh <nemeth at OOo>:
* hyphen.c: fix lefthyphenmin calculation for UTF-8 encoded input * hyphen.c: fix lefthyphenmin calculation for UTF-8 encoded input

View File

@ -17,21 +17,23 @@ char * mystrsep(char ** stringp, const char delim)
char * dp = (char *)memchr(mp,(int)((unsigned char)delim),n); char * dp = (char *)memchr(mp,(int)((unsigned char)delim),n);
if (dp) { if (dp) {
int nc; int nc;
*stringp = dp+1; *stringp = dp+1;
nc = (int)((unsigned long)dp - (unsigned long)mp); nc = (int)((unsigned long)dp - (unsigned long)mp);
rv = (char *) malloc(nc+1); rv = (char *) malloc(nc+1);
memcpy(rv,mp,nc); if (rv) {
*(rv+nc) = '\0'; memcpy(rv,mp,nc);
return rv; *(rv+nc) = '\0';
}
} else { } else {
rv = (char *) malloc(n+1); rv = (char *) malloc(n+1);
memcpy(rv, mp, n); if (rv) {
*(rv+n) = '\0'; memcpy(rv, mp, n);
*stringp = mp + n; *(rv+n) = '\0';
return rv; *stringp = mp + n;
}
} }
} }
return NULL; return rv;
} }