Skip to content

Commit

Permalink
- Properly get the length of the pointer.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19659 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Mar 20, 2014
1 parent c1d710c commit 1b9cc0a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions SimulationRuntime/c/meta/meta_modelica.c
Expand Up @@ -793,8 +793,10 @@ void changeStdStreamBuffer(void) {
char* getRecordElement(modelica_metatype arr, modelica_integer i) {
/* get the element from the record array */
void* name = (void*)mmc_gdb_arrayGet(0, arr, i);
char *displayName = NULL, *type = NULL, *formatString = NULL;
char nameStr[40];
sprintf(nameStr, "%ld", (long)name);

char *displayName = NULL, *type = NULL, *formatString = NULL;
/* get the name of the element */
getRecordElementName(arr, i - 2);
displayName = malloc(strlen(anyStringBuf) + 1);
Expand All @@ -807,8 +809,8 @@ char* getRecordElement(modelica_metatype arr, modelica_integer i) {

/* format the anyStringBuf as array to return it */
formatString = "^done,omc_recordelement={name=\"%ld\",displayName=\"%s\",type=\"%s\"}";
checkAnyStringBufSize(0, strlen(name) + strlen(displayName) + strlen(type) + strlen(formatString));
sprintf(anyStringBuf, formatString, (long (*) (long, long, long))name, displayName, type);
checkAnyStringBufSize(0, strlen(nameStr) + strlen(displayName) + strlen(type) + strlen(formatString) + 1);
sprintf(anyStringBuf, formatString, (long)name, displayName, type);

/* free the memory */
free(displayName);
Expand All @@ -824,17 +826,19 @@ char* getRecordElement(modelica_metatype arr, modelica_integer i) {
char* getListItem(modelica_metatype lst, modelica_integer i) {
/* get the item from the list */
void* name = (void*)mmc_gdb_listGet(0, lst, i);
char *displayName = NULL, *type = NULL, *formatString = NULL;
char nameStr[40];
sprintf(nameStr, "%ld", (long)name);

char *displayName = NULL, *type = NULL, *formatString = NULL;
/* get the type of the element */
getTypeOfAny(name);
type = malloc(strlen(anyStringBuf) + 1);
strcpy(type, anyStringBuf);

/* format the anyStringBuf as array to return it */
formatString = "^done,omc_listitem={name=\"%ld\",displayName=\"[%d]\",type=\"%s\"}";
checkAnyStringBufSize(0, strlen(name) + strlen(type) + strlen(formatString));
sprintf(anyStringBuf, formatString, (long (*) (long, long, long))name, i, type);
checkAnyStringBufSize(0, strlen(nameStr) + strlen(type) + strlen(formatString) + 1);
sprintf(anyStringBuf, formatString, (long)name, i, type);

/* free the memory */
free(type);
Expand Down

0 comments on commit 1b9cc0a

Please sign in to comment.