Skip to content

Commit

Permalink
Fixed bug in trimChar for empty strings and strings containing only o…
Browse files Browse the repository at this point in the history
…ne char that isn't trimmed away.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5578 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Otto Tronarp committed May 27, 2010
1 parent 74e5beb commit 07764b4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -216,6 +216,10 @@ RML_BEGIN_LABEL(System__trimChar)
int start_pos = 0;
int end_pos = length - 1;
char* res;
if (length == 0) {
rmlA0 = (void*) mk_scon("");
RML_TAILCALLK(rmlSC);
}
while(start_pos < end_pos){
if(str[start_pos] == char_to_be_trimmed)
start_pos++;
Expand All @@ -224,14 +228,13 @@ RML_BEGIN_LABEL(System__trimChar)
if(str[start_pos] != char_to_be_trimmed && str[end_pos] != char_to_be_trimmed)
break;
}
if(end_pos > start_pos){
if(end_pos >= start_pos){
res= (char*)malloc(end_pos - start_pos +2);
strncpy(res,&str[start_pos],end_pos - start_pos+1);
res[end_pos - start_pos+1] = '\0';
rmlA0 = (void*) mk_scon(res);
free(res);
RML_TAILCALLK(rmlSC);

}else{
rmlA0 = (void*) mk_scon("");
RML_TAILCALLK(rmlSC);
Expand Down

0 comments on commit 07764b4

Please sign in to comment.