[PATCH #45] Fixed uninitialized buffer in case of 0 dim and improved
efficiency in other cases.
This commit is contained in:
parent
6b6281d888
commit
282b53d51e
|
|
@ -38,24 +38,35 @@ dimstring(int *data, int length, char *retstring)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a string of the form "[12][1][10]".
|
* Create a string of the form "[12][1][10]" in retstring.
|
||||||
|
*
|
||||||
|
* Parameters
|
||||||
|
* dim_data: Array of sizes of dimensions, [12, 1, 10] for the example
|
||||||
|
* n_dim: Number of elements in the array, 3 in the example
|
||||||
|
* retstring: Address of buffer where the string is returned.
|
||||||
|
|
||||||
|
* Remarks
|
||||||
|
* It is assumed that the buffer in retstring is large enough, which for
|
||||||
|
* MAXDIMS, would require MAXDIMS * 12 + 1 bytes in the worst case assuming
|
||||||
|
* 32-bit ints. A looser but more general bound only assuming 8-bit bytes
|
||||||
|
* would be MAXDIMS * 3 * sizeof(int) + 1.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
indexstring(int *data, int length, char *retstring)
|
indexstring(const int *dim_data, int n_dim, char *retstring)
|
||||||
{
|
{
|
||||||
|
/* Handle case of no dimensions */
|
||||||
|
if (dim_data == (int *) NULL || n_dim < 1) {
|
||||||
|
*retstring = '\0';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Append each dimension */
|
||||||
int i;
|
int i;
|
||||||
char buf[BSIZE_SP];
|
for (i = 0; i < n_dim; i++) {
|
||||||
|
retstring += sprintf(retstring, "[%d]", dim_data[i]);
|
||||||
|
}
|
||||||
|
} /* end of function indexstring */
|
||||||
|
|
||||||
if (!data || length < 1)
|
|
||||||
retstring = "";
|
|
||||||
|
|
||||||
buf[0] = '\0';
|
|
||||||
|
|
||||||
for (i = 0; i < length; i++)
|
|
||||||
sprintf(buf + strlen(buf), "[%d]", data[i]);
|
|
||||||
|
|
||||||
strcpy(retstring, buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
#define ngspice_DIMENS_H
|
#define ngspice_DIMENS_H
|
||||||
|
|
||||||
void dimstring(int *data, int length, char *retstring);
|
void dimstring(int *data, int length, char *retstring);
|
||||||
void indexstring(int *data, int length, char *retstring);
|
void indexstring(const int *dim_data, int n_dim, char *retstring);
|
||||||
int incindex(int *counts, int numcounts, int *dims, int numdims);
|
int incindex(int *counts, int numcounts, int *dims, int numdims);
|
||||||
int emptydims(int *data, int length);
|
int emptydims(int *data, int length);
|
||||||
int atodims(char *p, int *data, int *outlength);
|
int atodims(char *p, int *data, int *outlength);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue