Skip to content
Snippets Groups Projects
Commit 910f640e authored by Thomas Jahns's avatar Thomas Jahns :cartwheel:
Browse files

Fix bug in buffer size of C++ wrapper.

parent d6e8fc8d
No related branches found
No related tags found
1 merge request!14Draft: K202125/cdi 1.8.x pio merge followup
......@@ -19,9 +19,9 @@ extern "C" {
*/
CdiGrid::CdiGrid() { gridID = -1; }
CdiGrid::CdiGrid(int gridid) {
char _name[CHARSIZE];
char _xname[CHARSIZE], _xlongname[CHARSIZE], _xstdname[CHARSIZE], _xunits[CHARSIZE];
char _yname[CHARSIZE], _ylongname[CHARSIZE], _ystdname[CHARSIZE], _yunits[CHARSIZE];
char _name[CDI_MAX_NAME];
char _xname[CDI_MAX_NAME], _xlongname[CDI_MAX_NAME], _xstdname[CDI_MAX_NAME], _xunits[CDI_MAX_NAME];
char _yname[CDI_MAX_NAME], _ylongname[CDI_MAX_NAME], _ystdname[CDI_MAX_NAME], _yunits[CDI_MAX_NAME];
gridID = gridid;
type = gridInqType(gridID);
......@@ -208,7 +208,7 @@ CdiTaxis::~CdiTaxis() { if (taxisID >= 0) taxisID = -1; }
*/
CdiZaxis::CdiZaxis() { zaxisID = -1; }
CdiZaxis::CdiZaxis(int zaxisid) {
char name[CHARSIZE], longname[CHARSIZE], units[CHARSIZE];
char name[CDI_MAX_NAME], longname[CDI_MAX_NAME], units[CDI_MAX_NAME];
zaxisID = zaxisid;
size = zaxisInqSize(zaxisID);
......@@ -243,7 +243,7 @@ CdiZaxis::~CdiZaxis() { if (zaxisID >= 0) zaxisID = -1; }
*/
CdiVariable::CdiVariable() { size = -1; }
CdiVariable::CdiVariable(int streamid,int vlistid, int varid) {
char _name[CHARSIZE],_longname[CHARSIZE], _units[CHARSIZE], _stdname[CHARSIZE];
char _name[CDI_MAX_NAME],_longname[CDI_MAX_NAME], _units[CDI_MAX_NAME], _stdname[CDI_MAX_NAME];
streamID = streamid;
vlistID = vlistid;
varID = varid;
......@@ -399,7 +399,7 @@ Cdi::getGrids() {
void
Cdi::getVars() {
char name[CHARSIZE];
char name[CDI_MAX_NAME];
int varID, code;
// std::cout << vlistID << std::endl;
for (varID = 0; varID < nvars; varID++)
......
......@@ -5,7 +5,9 @@
// (2.0.7 and earlier) with newer STL which no longer include cstddef
#include <cstddef>
#define CHARSIZE 128
extern "C" {
#include <cdi.h>
}
class CdiGrid {
public:
......@@ -44,7 +46,7 @@ class CdiTaxis {
int ntsteps, unit;
int rdate, rtime, vdate, vtime;
int type, calendar, hasBounds;
char name[CHARSIZE];
char name[CDI_MAX_NAME];
const char *unitname;
};
......
......@@ -29017,7 +29017,7 @@ _wrap_CdiTaxis_name_set(int argc, VALUE *argv, VALUE self) {
char *arg2 ;
void *argp1 = 0 ;
int res1 = 0 ;
char temp2[128] ;
char temp2[CDI_MAX_NAME] ;
int res2 ;
if ((argc < 1) || (argc > 1)) {
......@@ -29028,13 +29028,13 @@ _wrap_CdiTaxis_name_set(int argc, VALUE *argv, VALUE self) {
SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "CdiTaxis *","name", 1, self ));
}
arg1 = reinterpret_cast< CdiTaxis * >(argp1);
res2 = SWIG_AsCharArray(argv[0], temp2, 128);
res2 = SWIG_AsCharArray(argv[0], temp2, CDI_MAX_NAME);
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "char [128]","name", 2, argv[0] ));
SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "char [CDI_MAX_NAME]","name", 2, argv[0] ));
}
arg2 = reinterpret_cast< char * >(temp2);
if (arg2) memcpy(arg1->name,arg2,128*sizeof(char));
else memset(arg1->name,0,128*sizeof(char));
if (arg2) memcpy(arg1->name,arg2,CDI_MAX_NAME*sizeof(char));
else memset(arg1->name,0,CDI_MAX_NAME*sizeof(char));
return Qnil;
fail:
return Qnil;
......@@ -29059,7 +29059,7 @@ _wrap_CdiTaxis_name_get(int argc, VALUE *argv, VALUE self) {
arg1 = reinterpret_cast< CdiTaxis * >(argp1);
result = (char *)(char *) ((arg1)->name);
{
size_t size = SWIG_strnlen(result, 128);
size_t size = SWIG_strnlen(result, CDI_MAX_NAME);
......@@ -33576,7 +33576,6 @@ SWIGEXPORT void Init_CdiObj(void) {
SwigClassGridsMap.mark = 0;
SwigClassGridsMap.destroy = (void (*)(void *)) free_std_map_Sl_int_Sc_CdiGrid_Sg_;
SwigClassGridsMap.trackObjects = 0;
rb_define_const(mCdiObj, "CHARSIZE", SWIG_From_int(static_cast< int >(128)));
SwigClassCdiGrid.klass = rb_define_class_under(mCdiObj, "CdiGrid", rb_cObject);
SWIG_TypeClientData(SWIGTYPE_p_CdiGrid, (void *) &SwigClassCdiGrid);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment