Skip to content

Commit

Permalink
- Fix System.snprintff - check for negative length
Browse files Browse the repository at this point in the history
- Pass positive length in hpcom


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17796 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 21, 2013
1 parent 9a2f9b6 commit 923b663
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Compiler/BackEnd/HpcOmTaskGraph.mo
Expand Up @@ -2448,7 +2448,7 @@ algorithm
((schedulerThreadId,schedulerTaskNumber)) = arrayGet(schedulerInfo,nodeIdx);
threadIdxString = "Th " +& intString(schedulerThreadId);
taskNumberString = intString(schedulerTaskNumber);
calcTimeString = System.snprintff("%.0f", -1, calcTime);
calcTimeString = System.snprintff("%.0f", 25, calcTime);
additionalLabels = {GraphML.NODELABEL_CORNER(calcTimeString, GraphML.COLOR_YELLOW, GraphML.FONTBOLD(), "se")};
//print("Node " +& intString(nodeIdx) +& " has child nodes " +& stringDelimitList(List.map(childNodes,intString),", ") +& "\n");
tmpGraph = GraphML.addNode("Node" +& intString(nodeIdx), componentsString, GraphML.COLOR_ORANGE, GraphML.RECTANGLE(), SOME(nodeDesc), {((nameAttIdx,compText)),((calcTimeAttIdx,calcTimeString)),((opCountAttIdx, opCountString)),((taskIdAttIdx,componentsString)),((yCoordAttIdx,yCoordString)),((simCodeEqAttIdx,simCodeEqString)),((threadIdAttIdx,threadIdxString)),((taskNumberAttIdx,taskNumberString))}, additionalLabels, iGraph);
Expand Down Expand Up @@ -2480,7 +2480,7 @@ algorithm
threadIdxString = "Th " +& intString(schedulerThreadId);
taskNumberString = intString(schedulerTaskNumber);

calcTimeString = System.snprintff("%.0f", -1, calcTime);
calcTimeString = System.snprintff("%.0f", 25, calcTime);
additionalLabels = {GraphML.NODELABEL_CORNER(calcTimeString, GraphML.COLOR_YELLOW, GraphML.FONTBOLD(), "se")};
//print("Node " +& intString(nodeIdx) +& " has child nodes " +& stringDelimitList(List.map(childNodes,intString),", ") +& "\n");
tmpGraph = GraphML.addNode("Node" +& intString(nodeIdx), componentsString, GraphML.COLOR_ORANGE, GraphML.RECTANGLE(), SOME(nodeDesc), {((nameAttIdx,compText)),((calcTimeAttIdx,calcTimeString)),((opCountAttIdx, opCountString)),((taskIdAttIdx,componentsString)), ((simCodeEqAttIdx,simCodeEqString)),((threadIdAttIdx,threadIdxString)),((taskNumberAttIdx,taskNumberString))}, additionalLabels, iGraph);
Expand Down
9 changes: 7 additions & 2 deletions Compiler/runtime/System_omc.c
Expand Up @@ -673,9 +673,14 @@ extern const char* System_getMakeCommand()

extern const char* System_snprintff(const char *fmt, int len, double d)
{
char *buf = ModelicaAllocateString(len);
if (snprintf(buf,len,fmt,d) >= len)
char *buf;
if (len < 0) {
MMC_THROW();
}
buf = ModelicaAllocateString(len);
if (snprintf(buf,len,fmt,d) >= len) {
MMC_THROW();
}
return buf;
}

Expand Down
14 changes: 10 additions & 4 deletions Compiler/runtime/System_rml.c
Expand Up @@ -1702,10 +1702,16 @@ RML_BEGIN_LABEL(System__snprintff)
const char *fmt = RML_STRINGDATA(rmlA0);
long len = RML_UNTAGFIXNUM(rmlA1);
double d = rml_prim_get_real(rmlA2);
char buf[len];
snprintf(buf,len,fmt,d);
buf[len-1] = 0;
rmlA0 = mk_scon(buf);
if (len > 0) {
char buf[len];
if (snprintf(buf,len,fmt,d) >= len) {
RML_TAILCALLK(rmlFC);
}
buf[len-1] = 0;
rmlA0 = mk_scon(buf);
} else {
RML_TAILCALLK(rmlFC);
}
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL
Expand Down

0 comments on commit 923b663

Please sign in to comment.