Skip to content

Commit

Permalink
- Fix MM listDelete() for index other than 0
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7167 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Nov 24, 2010
1 parent 42f902b commit d8ef1b0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions c_runtime/meta_modelica_builtin.cpp
Expand Up @@ -568,7 +568,7 @@ listDelete_rettype listDelete(modelica_metatype lst, modelica_integer ix)
throw 1;
return MMC_CDR(lst);
}
tmpArr = (modelica_metatype *) malloc(sizeof(modelica_metatype)*ix); /* We know the size of the first part of the list (+1 for the element to delete) */
tmpArr = (modelica_metatype *) malloc(sizeof(modelica_metatype)*(ix)); /* We know the size of the first part of the list (+1 for the element to delete) */
if (tmpArr == NULL) {
fprintf(stderr, "%s:%d: malloc failed", __FILE__, __LINE__);
EXIT(1);
Expand All @@ -584,7 +584,12 @@ listDelete_rettype listDelete(modelica_metatype lst, modelica_integer ix)
tmpArr[i] = MMC_CAR(lst);
lst = MMC_CDR(lst);
}
for (i=ix-2; i>=0; i--)
if (listEmpty(lst)) {
free(tmpArr);
throw 1;
}
lst = MMC_CDR(lst);
for (i=ix-1; i>=0; i--)
{
lst = mmc_mk_cons(tmpArr[i], lst);
}
Expand Down

0 comments on commit d8ef1b0

Please sign in to comment.