From ef6c8abb6c50ea314b63282d666cd1a694ee3491 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Wed, 12 Feb 2020 22:48:16 +0100 Subject: [PATCH] Fix of buffer overrun in interpolation at endpoint of interval. Made cfunc.mod for tables more modular. Prevented buffer overrun when building file name. Added error checking for allocation failures in many locations. Made binary search for interpolation more efficient. --- src/xspice/icm/table/support/gettokens.h | 10 ++++++ src/xspice/icm/table/support/table_util.h | 38 +++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/xspice/icm/table/support/gettokens.h create mode 100644 src/xspice/icm/table/support/table_util.h diff --git a/src/xspice/icm/table/support/gettokens.h b/src/xspice/icm/table/support/gettokens.h new file mode 100644 index 000000000..fef240af4 --- /dev/null +++ b/src/xspice/icm/table/support/gettokens.h @@ -0,0 +1,10 @@ +#ifndef gettokens_h_included +#define gettokens_h_included + +/* Type definition for each possible token returned. */ +typedef enum token_type_s { CNV_NO_TOK, CNV_STRING_TOK } Cnv_Token_Type_t; + +char * CNVget_token(char **s, Cnv_Token_Type_t *type); +char *CNVgettok(char **s); +int cnv_get_spice_value(char *str, double *p_value); +#endif /* gettokens_h_included */ diff --git a/src/xspice/icm/table/support/table_util.h b/src/xspice/icm/table/support/table_util.h new file mode 100644 index 000000000..88bf059e3 --- /dev/null +++ b/src/xspice/icm/table/support/table_util.h @@ -0,0 +1,38 @@ +#include "eno2.h" +#include "eno3.h" + +typedef struct { + int ix; /* size of array in x */ + int iy; /* size of array in y */ + int iz; /* size of array in z */ + + sf_eno3 newtable; /* the table, code borrowed from madagascar project */ + + /* Input values corresponding to each index. They define the value + * in the domain at each index value */ + double *xcol; /* array of doubles in x */ + double *ycol; /* array of doubles in y */ + double *zcol; /* array of doubles in z */ + + double ***table; /* f(xi, yj, zk) */ +} Table3_Data_t; + +void free_local_data(Table3_Data_t *loc); + + +Table3_Data_t *init_local_data(const char *filename, int order); + +/* Finds difference between column values */ +static inline double get_local_diff(int n, double *col, int ind) +{ + if (ind >= n - 1) { + return col[n - 1] - col[n - 2]; + } + if (ind <= 0) { + return col[1] - col[0]; + } + return 0.5 * (col[ind + 1] - col[ind - 1]); +} /* end of function get_local_diff */ + + +