Scierror(888, _("%s : type 2 function not allowed for scilab blocks\n"), fname);
return 0;
case 3:
- Block.funpt = sciblk2;
+ Block.funpt = (voidg) sciblk2;
Block.type = 2;
break;
case 5:
- Block.funpt = sciblk4;
+ Block.funpt = (voidg) sciblk4;
Block.type = 4;
break;
case 99: /* debugging block */
- Block.funpt = sciblk4;
+ Block.funpt = (voidg) sciblk4;
Block.type = 4;
break;
case 10005:
- Block.funpt = sciblk4;
+ Block.funpt = (voidg) sciblk4;
Block.type = 10004;
break;
default :
}
else if (lfunpt <= ntabsim)
{
- Block.funpt = *(tabsim[lfunpt - 1].fonc);
+ Block.funpt = (voidg) * (tabsim[lfunpt - 1].fonc);
Block.scsptr = 0;
}
else
ilh = (int *) (listentry(il1, n));
mh = ilh[1];
nh = ilh[2];
- Block.label = "";
if (mh * nh != 0)
{
len_str = ilh[5] - 1;
- if (len_str != 0)
+ if (len_str < 0)
{
- if ((Block.label = (char *) MALLOC((len_str + 1) * sizeof(char))) == NULL)
- {
- for (j = 0; j < Block.nin; j++)
- {
- FREE(Block.inptr[j]);
- }
- FREE(Block.inptr);
- FREE(Block.insz);
- for (j = 0; j < Block.nout; j++)
- {
- FREE(Block.outptr[j]);
- }
- FREE(Block.outptr);
- FREE(Block.outsz);
- FREE(Block.evout);
- FREE(Block.x);
- FREE(Block.xd);
- FREE(Block.xprop);
- FREE(Block.res);
- FREE(Block.z);
- FREE(Block.ozsz);
- FREE(Block.oztyp);
- for (j = 0; j < Block.noz; j++)
- {
- FREE(Block.ozptr[j]);
- }
- FREE(Block.rpar);
- FREE(Block.ipar);
- FREE(Block.oparsz);
- FREE(Block.opartyp);
- for (j = 0; j < Block.nopar; j++)
- {
- FREE(Block.oparptr[j]);
- }
- Scierror(888, _("%s : Allocation error.\n"), fname);
- return 0;
- }
- Block.label[len_str] = '\0';
- C2F(cvstr)(&len_str, &ilh[6], Block.label, (j = 1, &j), len_str);
+ len_str = 0;
+ }
+ }
+ else
+ {
+ len_str = 0;
+ }
+ if ((Block.label = (char *) MALLOC((len_str + 1) * sizeof(char))) == NULL)
+ {
+ for (j = 0; j < Block.nin; j++)
+ {
+ FREE(Block.inptr[j]);
+ }
+ FREE(Block.inptr);
+ FREE(Block.insz);
+ for (j = 0; j < Block.nout; j++)
+ {
+ FREE(Block.outptr[j]);
}
+ FREE(Block.outptr);
+ FREE(Block.outsz);
+ FREE(Block.evout);
+ FREE(Block.x);
+ FREE(Block.xd);
+ FREE(Block.xprop);
+ FREE(Block.res);
+ FREE(Block.z);
+ FREE(Block.ozsz);
+ FREE(Block.oztyp);
+ for (j = 0; j < Block.noz; j++)
+ {
+ FREE(Block.ozptr[j]);
+ }
+ FREE(Block.rpar);
+ FREE(Block.ipar);
+ FREE(Block.oparsz);
+ FREE(Block.opartyp);
+ for (j = 0; j < Block.nopar; j++)
+ {
+ FREE(Block.oparptr[j]);
+ }
+ Scierror(888, _("%s : Allocation error.\n"), fname);
+ return 0;
+ }
+
+ Block.label[len_str] = '\0';
+ if (len_str > 0)
+ {
+ C2F(cvstr)(&len_str, &ilh[6], Block.label, (j = 1, &j), len_str);
}
/* zero crossing */
{
FREE(Block.oparptr[j]);
}
- if (len_str != 0)
- {
- FREE(Block.label);
- }
+ FREE(Block.label);
FREE(Block.g);
FREE(Block.jroot);
FREE(Block.mode);
int i = 0, j = 0, k = 0; /*local counter variable*/
int sz_str = 0; /*local variable to store size of string*/
int err_check = 0; /*local variable for cross var. checking dimension*/
+ char* error = NULL;
+ BOOL allocatedError = FALSE;
+#define MAX_ERROR_LEN 512
/*definition of min/max input/output argument*/
static int minlhs = 1, maxlhs = 2;
FREE(lfunpt);
freeparam;
FREE(outtb_elem);
+ return 0;
break;
}
break;
switch (ierr)
{
case 1 :
- strcpy(C2F(cha1).buf, _("scheduling problem"));
+ error = _("scheduling problem");
C2F(curblk).kfun = 0;
break;
case 2 :
- strcpy(C2F(cha1).buf, _("input to zero-crossing stuck on zero"));
+ error = _("input to zero-crossing stuck on zero");
C2F(curblk).kfun = 0;
break;
case 3 :
- strcpy(C2F(cha1).buf, _("event conflict"));
+ error = _("event conflict");
C2F(curblk).kfun = 0;
break;
case 4 :
- strcpy(C2F(cha1).buf, _("algebraic loop detected"));
+ error = _("algebraic loop detected");
C2F(curblk).kfun = 0;
break;
case 5 :
- strcpy(C2F(cha1).buf, _("cannot allocate memory"));
+ error = _("cannot allocate memory");
C2F(curblk).kfun = 0;
break;
case 6 :
- sprintf(C2F(cha1).buf, _("the block %d has been called with input out of its domain"), C2F(curblk).kfun);
+ error = MALLOC(MAX_ERROR_LEN);
+ if (error != NULL)
+ {
+ allocatedError = TRUE;
+ snprintf(error, MAX_ERROR_LEN, _("the block %d has been called with input out of its domain"), C2F(curblk).kfun);
+ }
+ else
+ {
+ error = _("cannot allocate memory");
+ }
break;
case 7 :
- strcpy(C2F(cha1).buf, _("singularity in a block"));
+ error = _("singularity in a block");
break;
case 8 :
- strcpy(C2F(cha1).buf, _("block produces an internal error"));
+ error = _("block produces an internal error");
break;
case 10 :
- strcpy(C2F(cha1).buf, coserr.buf);
+ error = coserr.buf;
break;
case 20 :
- strcpy(C2F(cha1).buf, _("initial conditions not converging"));
+ error = _("initial conditions not converging");
break;
case 21 :
- sprintf(C2F(cha1).buf, _("cannot allocate memory in block=%d"), C2F(curblk).kfun);
+ error = MALLOC(MAX_ERROR_LEN);
+ if (error != NULL)
+ {
+ allocatedError = TRUE;
+ snprintf(error, MAX_ERROR_LEN, _("cannot allocate memory in block=%d"), C2F(curblk).kfun);
+ }
+ else
+ {
+ error = _("cannot allocate memory");
+ }
break;
case 22 :
- strcpy(C2F(cha1).buf, _("sliding mode condition, cannot integrate"));
+ error = _("sliding mode condition, cannot integrate");
break;
case 23 :
- strcpy(C2F(cha1).buf, _("Cannot find the initial mode, maybe there is a sliding mode condition"));
+ error = _("Cannot find the initial mode, maybe there is a sliding mode condition");
break;
case 24 :
- strcpy(C2F(cha1).buf, _("You have changed a parameter in your model, but the model has been compiled to use an XML file containing initial values and parameters. So you should either recompile your Scicos diagram or [re]launch the initialization interface to regenerate the XML file with new parameters."));
+ error = _("You have changed a parameter in your model, but the model has been compiled to use an XML file containing initial values and parameters. So you should either recompile your Scicos diagram or [re]launch the initialization interface to regenerate the XML file with new parameters.");
break;
case 25 :
- strcpy(C2F(cha1).buf, _("Undefined data type."));
+ error = _("Undefined data type.");
break;
case 26 :
- strcpy(C2F(cha1).buf, _("The number of parameter provided by Scicos blocks is different from what expected by the code generated by the Modelica compiler. You might have relaxed a parameter using FIXED property (i.e., fixed=false) in a Modelica model. This will be corrected in the next version"));
+ error = _("The number of parameter provided by Scicos blocks is different from what expected by the code generated by the Modelica compiler. You might have relaxed a parameter using FIXED property (i.e., fixed=false) in a Modelica model. This will be corrected in the next version");
break;
/*In this case, you need to turn off the parameter embedded code generation mode by setting Modelica_ParEmb=%f in the Scilab command window, and recompile the Scicos diagram*/
default :
if (ierr >= 1000)
{
- strcpy(C2F(cha1).buf, _("unknown or erroneous block"));
+ error = _("unknown or erroneous block");
}
else if (ierr >= 201 && ierr <= 416) /* Sundials error messages, stocked in coserr.buf */
{
- strcpy(C2F(cha1).buf, coserr.buf);
+ error = coserr.buf;
}
else if (ierr >= 100)
{
istate = -(ierr - 100);
- sprintf(C2F(cha1).buf, _("integration problem istate=%d"), istate);
+ error = MALLOC(MAX_ERROR_LEN);
+ if (error != NULL)
+ {
+ allocatedError = TRUE;
+ snprintf(error, MAX_ERROR_LEN, _("integration problem istate=%d"), istate);
+ }
+ else
+ {
+ error = _("cannot allocate memory");
+ }
C2F(curblk).kfun = 0;
}
else
{
- strcpy(C2F(cha1).buf, _("scicos unexpected error, please report..."));
+ error = _("scicos unexpected error, please report...");
C2F(curblk).kfun = 0;
}
break;
}
if (! (C2F(errgst).err1 > 0 || C2F(iop).err > 0))
{
- Scierror(888, "%s\n", C2F(cha1).buf);
+ Scierror(888, "%s\n", error);
+ if (allocatedError)
+ {
+ FREE(error);
+ }
/*C2F(curblk).kfun=0;*/
C2F(com).fun = 0; /*set common fun=0 (this disable bug in debug mode)*/
freeparam;
/* Scicos
*
* Copyright (C) INRIA - Alan LAYEC
+* Copyright (C) 2013 - Scilab Enterprises - Clement DAVID
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
nh = ilh[2];
Block->z = NULL;
assert(Block->nz == mh * nh);
+ assert(mh * nh >= 0);
if (mh * nh > 0)
{
if ((Block->z = (double *) MALLOC(Block->nz * sizeof(double))) == NULL)
nh = ilh[2];
Block->ozsz = NULL;
assert(2 * Block->noz == mh * nh);
+ assert(mh * nh >= 0);
if (mh * nh > 0)
{
if ((Block->ozsz = (int *) MALLOC(2 * Block->noz * sizeof(int))) == NULL)
nh = ilh[2];
Block->oztyp = NULL;
assert(Block->noz == mh * nh);
+ assert(mh * nh >= 0);
if (mh * nh > 0)
{
if ((Block->oztyp = (int *) MALLOC(Block->noz * sizeof(int))) == NULL)
mh2 = ilh2[1];
nh2 = ilh2[2];
Block->ozptr[i] = NULL;
+ assert(mh2 * nh2 >= 0);
switch (Block->oztyp[i])
{
case 10 :
nh = ilh[2];
Block->x = NULL;
assert(Block->nx == mh * nh);
+ assert(mh * nh >= 0);
if (mh * nh > 0)
{
if ((Block->x = (double *) MALLOC(Block->nx * sizeof(double))) == NULL)
nh = ilh[2];
Block->xd = NULL;
assert(Block->nx == mh * nh);
+ assert(mh * nh >= 0);
if (mh * nh > 0)
{
if ((Block->xd = (double *) MALLOC(Block->nx * sizeof(double))) == NULL)
nh = ilh[2];
Block->res = NULL;
assert(Block->nx == mh * nh);
+ assert(mh * nh >= 0);
if (mh * nh > 0)
{
if ((Block->res = (double *) MALLOC(Block->nx * sizeof(double))) == NULL)
nh = ilh[2];
Block->insz = NULL;
assert(3 * Block->nin == mh * nh);
+ assert(mh * nh >= 0);
if (mh * nh > 0)
{
if ((Block->insz = (int *) MALLOC(3 * Block->nin * sizeof(int))) == NULL)
nh = ilh[2];
Block->inptr = NULL;
assert(Block->nin == mh);
+ assert(mh >= 0);
if (Block->nin > 0)
{
if ((Block->inptr = (void **) MALLOC(Block->nin * sizeof(void *))) == NULL)
mh2 = ilh2[1];
nh2 = ilh2[2];
Block->inptr[i] = NULL;
+ assert(mh2 * nh2 >= 0);
switch (Block->insz[2 * Block->nin + i])
{
case 10 :
nh = ilh[2];
Block->outsz = NULL;
assert(3 * Block->nout == mh * nh);
+ assert(mh * nh >= 0);
if (mh * nh > 0)
{
if ((Block->outsz = (int *) MALLOC(3 * Block->nout * sizeof(int))) == NULL)
nh = ilh[2];
Block->outptr = NULL;
assert(Block->nout == mh);
+ assert(mh >= 0);
if (Block->nout > 0)
{
if ((Block->outptr = (void **) MALLOC(Block->nout * sizeof(void *))) == NULL)
mh2 = ilh2[1];
nh2 = ilh2[2];
Block->outptr[i] = NULL;
+ assert(mh2 * nh2 >= 0);
switch (Block->outsz[2 * Block->nout + i])
{
case 10 :
nh = ilh[2];
Block->evout = NULL;
assert(Block->nevout == mh * nh);
+ assert(mh * nh >= 0);
if (mh * nh > 0)
{
if ((Block->evout = (double *) MALLOC(Block->nevout * sizeof(double))) == NULL)
nh = ilh[2];
Block->rpar = NULL;
assert(Block->nrpar == mh * nh);
+ assert(mh * nh >= 0);
if (mh * nh > 0)
{
if ((Block->rpar = (double *) MALLOC(Block->nrpar * sizeof(double))) == NULL)
nh = ilh[2];
Block->ipar = NULL;
assert(Block->nipar == mh * nh);
+ assert(mh * nh >= 0);
if (mh * nh > 0)
{
if ((Block->ipar = (int *) MALLOC(Block->nipar * sizeof(int))) == NULL)
nh = ilh[2];
Block->oparsz = NULL;
assert(2 * Block->nopar == mh * nh);
+ assert(mh * nh >= 0);
if (mh * nh > 0)
{
if ((Block->oparsz = (int *) MALLOC(2 * Block->nopar * sizeof(int))) == NULL)
nh = ilh[2];
Block->opartyp = NULL;
assert(Block->nopar == mh * nh);
+ assert(mh * nh >= 0);
if (mh * nh > 0)
{
if ((Block->opartyp = (int *) MALLOC(Block->nopar * sizeof(int))) == NULL)
nh = ilh[2];
Block->oparptr = NULL;
assert(Block->nopar == mh);
+ assert(mh >= 0);
if (Block->nopar > 0)
{
if ((Block->oparptr = (void **) MALLOC(Block->nopar * sizeof(void *))) == NULL)
mh2 = ilh2[1];
nh2 = ilh2[2];
Block->oparptr[i] = NULL;
+ assert(mh2 * nh2 >= 0);
switch (Block->opartyp[i])
{
case 10 :
nh = ilh[2];
Block->g = NULL;
assert(Block->ng == mh * nh);
+ assert(mh * nh >= 0);
if (mh * nh > 0)
{
if ((Block->g = (double *) MALLOC(Block->ng * sizeof(double))) == NULL)
mh = ilh[1];
nh = ilh[2];
Block->jroot = NULL;
+ assert(mh * nh >= 0);
if (mh * nh > 0)
{
if ((Block->jroot = (int *) MALLOC((mh * nh) * sizeof(int))) == NULL)
ilh = (int *) (listentry(il, n));
mh = ilh[1];
nh = ilh[2];
- Block->label = "";
- if (mh * nh > 0)
+ Block->label = NULL;
+ if (mh * nh != 0)
{
- len_str = ilh[4 + mh * nh] + 1;
- if (len_str > 0)
+ len_str = ilh[5] - 1;
+ if (len_str < 0)
{
- if ((Block->label = (char *) MALLOC((len_str + 1) * sizeof(char))) == NULL)
- {
- FREE(Block->z);
- FREE(Block->ozsz);
- FREE(Block->oztyp);
- for (j = 0; j < Block->noz; j++)
- {
- FREE(Block->ozptr[j]);
- }
- FREE(Block->ozptr);
- FREE(Block->x);
- FREE(Block->xd);
- FREE(Block->res);
- FREE(Block->insz);
- for (j = 0; j < Block->nin; j++)
- {
- FREE(Block->inptr[j]);
- }
- FREE(Block->inptr);
- FREE(Block->outsz);
- for (j = 0; j < Block->nout; j++)
- {
- FREE(Block->outptr[j]);
- }
- FREE(Block->outptr);
- FREE(Block->evout);
- FREE(Block->rpar);
- FREE(Block->ipar);
- FREE(Block->oparsz);
- FREE(Block->opartyp);
- for (j = 0; j < Block->nopar; j++)
- {
- FREE(Block->oparptr[j]);
- }
- FREE(Block->oparptr);
- FREE(Block->g);
- FREE(Block->jroot);
- *ierr = -39;
- return 0;
- }
- Block->label[len_str] = '\0';
- C2F(cvstr)(&len_str, &ilh[4 + mh * nh + 1], Block->label, (j = 1, &j), len_str);
+ len_str = 0;
}
}
+ else
+ {
+ len_str = 0;
+ }
+ if ((Block->label = (char *) MALLOC((len_str + 1) * sizeof(char))) == NULL)
+ {
+ FREE(Block->z);
+ FREE(Block->ozsz);
+ FREE(Block->oztyp);
+ for (j = 0; j < Block->noz; j++)
+ {
+ FREE(Block->ozptr[j]);
+ }
+ FREE(Block->ozptr);
+ FREE(Block->x);
+ FREE(Block->xd);
+ FREE(Block->res);
+ FREE(Block->insz);
+ for (j = 0; j < Block->nin; j++)
+ {
+ FREE(Block->inptr[j]);
+ }
+ FREE(Block->inptr);
+ FREE(Block->outsz);
+ for (j = 0; j < Block->nout; j++)
+ {
+ FREE(Block->outptr[j]);
+ }
+ FREE(Block->outptr);
+ FREE(Block->evout);
+ FREE(Block->rpar);
+ FREE(Block->ipar);
+ FREE(Block->oparsz);
+ FREE(Block->opartyp);
+ for (j = 0; j < Block->nopar; j++)
+ {
+ FREE(Block->oparptr[j]);
+ }
+ FREE(Block->oparptr);
+ FREE(Block->g);
+ FREE(Block->jroot);
+ *ierr = -39;
+ return 0;
+ }
+ Block->label[len_str] = '\0';
+ if (len_str > 0)
+ {
+ C2F(cvstr)(&len_str, &ilh[4 + mh * nh + 1], Block->label, (j = 1, &j), len_str);
+ }
/* 37 - work*/
n = MlistGetFieldNumber(il, "work");
FREE(Block->oparptr);
FREE(Block->g);
FREE(Block->jroot);
- if (len_str != 0)
- {
- FREE(Block->label);
- }
+ FREE(Block->label);
*ierr = 98;
return 0;
}
ilh = (int *) (listentry(il, n));
mh = ilh[1];
nh = ilh[2];
- Block->work = (void**) ((int) * ((double *)(&ilh[4])));
+ // pointer value is stored on double values, restoring as a copy will take
+ // care of alignement issues and pointer size issues.
+ memcpy(&Block->work, &ilh[4], sizeof(void**));
/* 38 - nmode*/
n = MlistGetFieldNumber(il, "nmode");
FREE(Block->oparptr);
FREE(Block->g);
FREE(Block->jroot);
- if (len_str != 0)
- {
- FREE(Block->label);
- }
+ FREE(Block->label);
*ierr = 98;
return 0;
}
FREE(Block->oparptr);
FREE(Block->g);
FREE(Block->jroot);
- if (len_str != 0)
- {
- FREE(Block->label);
- }
+ FREE(Block->label);
*ierr = 98;
return 0;
}
nh = ilh[2];
Block->mode = NULL;
assert(Block->nmode == mh * nh);
+ assert(mh * nh >= 0);
if (Block->nmode > 0)
{
if ((Block->mode = (int *) MALLOC(Block->nmode * sizeof(int))) == NULL)
FREE(Block->oparptr);
FREE(Block->g);
FREE(Block->jroot);
- if (len_str != 0)
- {
- FREE(Block->label);
- }
+ FREE(Block->label);
*ierr = -39;
return 0;
}
FREE(Block->oparptr);
FREE(Block->g);
FREE(Block->jroot);
- if (len_str != 0)
- {
- FREE(Block->label);
- }
+ FREE(Block->label);
FREE(Block->mode);
*ierr = 98;
return 0;
mh = ilh[1];
nh = ilh[2];
Block->xprop = NULL;
+ assert(mh * nh >= 0);
if (mh * nh > 0)
{
if ((Block->xprop = (int *) MALLOC((mh * nh) * sizeof(int))) == NULL)
FREE(Block->oparptr);
FREE(Block->g);
FREE(Block->jroot);
- if (len_str != 0)
- {
- FREE(Block->label);
- }
+ FREE(Block->label);
FREE(Block->mode);
*ierr = -39;
return 0;