Skip to content

Commit

Permalink
- Ugly, ugly hack to keep anyString and getTypeOfAny from segfaulting on
Browse files Browse the repository at this point in the history
  function pointers.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11106 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Feb 13, 2012
1 parent 39f9b13 commit 9d09d76
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions SimulationRuntime/c/meta/meta_modelica.c
Expand Up @@ -249,6 +249,15 @@ inline static int anyStringWork(void* any, int ix)
numslots = MMC_HDRSLOTS(hdr);
ctor = MMC_HDRCTOR(hdr);

/* Ugly hack to "detect" function pointers. If these parameters are outside
* these bounds, then we probably have a function pointer. This is just to
* keep the debugger from crashing. */
if (numslots < 0 || numslots > 1024 || ctor > 255) {
checkAnyStringBufSize(ix, 2);
ix += sprintf(anyStringBuf+ix, "0");
return ix;
}

if (numslots>0 && ctor == MMC_FREE_OBJECT_CTOR) { /* FREE OBJECT! */
checkAnyStringBufSize(ix,100);
ix += sprintf(anyStringBuf+ix, "FREE(%u)", numslots);
Expand Down Expand Up @@ -505,6 +514,15 @@ inline static int getTypeOfAnyWork(void* any, int ix) /* for debugging */
numslots = MMC_HDRSLOTS(hdr);
ctor = 255 & (hdr >> 2);

/* Ugly hack to "detect" function pointers. If these parameters are outside
* these bounds, then we probably have a function pointer. This is just to
* keep the debugger from crashing. */
if (numslots < 0 || numslots > 1024 || ctor > 255) {
checkAnyStringBufSize(ix, 8);
ix += sprintf(anyStringBuf+ix, "%s", "Integer");
return ix;
}

if (numslots>0 && ctor == MMC_ARRAY_TAG) {
checkAnyStringBufSize(ix,7);
ix += sprintf(anyStringBuf+ix, "Array<");
Expand Down

0 comments on commit 9d09d76

Please sign in to comment.