Skip to content

Commit

Permalink
Error handling more secure
Browse files Browse the repository at this point in the history
  • Loading branch information
mooiman committed Sep 12, 2023
1 parent 8113aff commit 33d1a7c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
3 changes: 2 additions & 1 deletion packages/include/MyDrawingCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ private slots:


public:
MyCanvas(QgisInterface *);
MyCanvas();
MyCanvas(QgisInterface*);
~MyCanvas();

void empty_cache(drawing_cache);
Expand Down
2 changes: 1 addition & 1 deletion packages/qgis_umesh.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ call ..\scripts\git_insert_hash.cmd .\include qqis_umesh_version.rc</Command>
<DataExecutionPrevention>
</DataExecutionPrevention>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>c:\OSGeo4W\apps\qgis\plugins\$(ProjectName).pdb</ProgramDatabaseFile>
</Link>
<Bscmake>
Expand Down
8 changes: 7 additions & 1 deletion packages/src/MyDrawingCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ using namespace std;
//MapProperty * MapProperty::obj; // Initialize static member of class MapProperty (Singleton)
//
//
MyCanvas::MyCanvas() :
QgsMapTool(nullptr),
QgsMapCanvasItem(nullptr)
{
}
MyCanvas::MyCanvas(QgisInterface * QGisIface) :
QgsMapTool(QGisIface->mapCanvas()),
QgsMapCanvasItem(QGisIface->mapCanvas()),
Expand Down Expand Up @@ -1663,7 +1668,8 @@ bool MyCanvas::isFontAvailable(const char* name)
//
int MyCanvas::getTextWidth(const char* name)
{
int size = (mMapCanvas->fontMetrics()).width(name);
int size = (mMapCanvas->fontMetrics()).horizontalAdvance(name);

return size;
}
//
Expand Down
31 changes: 19 additions & 12 deletions packages/src/ugrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1679,16 +1679,18 @@ int UGRID::get_attribute(int ncid, int i_var, char * att_name, long * att_value)
return status;
}
//------------------------------------------------------------------------------
int UGRID::get_dimension(int ncid, char * dim_name, size_t * dim_length)
int UGRID::get_dimension(int ncid, char* dim_name, size_t* dim_length)
{
int dimid;
int status = -1;

*dim_length = 0;
if (dim_name != NULL && strlen(dim_name) != 0)
{
status = nc_inq_dimid(ncid, dim_name, &dimid);
status = nc_inq_dimlen(ncid, dimid, dim_length);
if (status == NC_NOERR)
{
status = nc_inq_dimlen(ncid, dimid, dim_length);
}
}
return status;
}
Expand All @@ -1698,11 +1700,13 @@ int UGRID::get_dimension(int ncid, std::string dim_name, size_t * dim_length)
int dimid;
int status = -1;

*dim_length = 0;
if (dim_name.size() != 0)
{
status = nc_inq_dimid(ncid, dim_name.c_str(), &dimid);
status = nc_inq_dimlen(ncid, dimid, dim_length);
if (status == NC_NOERR)
{
status = nc_inq_dimlen(ncid, dimid, dim_length);
}
}
return status;
}
Expand All @@ -1712,18 +1716,21 @@ int UGRID::get_dimension_var(int ncid, std::string var_name, size_t * dim_length
// get the total dimension length in bytes of the var_name variable
int dimid;
int status = -1;
*dim_length = 0;

if (var_name.size() != 0)
{
int janm;
status = nc_inq_varid(ncid, var_name.c_str(), &dimid);
status = nc_inq_vardimid(ncid, dimid, &janm);
char * tmp_value = (char *)malloc(sizeof(char) * (NC_MAX_NAME + 1));;
status = nc_inq_dimname(ncid, janm, tmp_value);
status = get_dimension(ncid, tmp_value, dim_length);
free(tmp_value);
tmp_value = nullptr;
if (status == NC_NOERR)
{
*dim_length = 0;
status = nc_inq_vardimid(ncid, dimid, &janm);
char* tmp_value = (char*)malloc(sizeof(char) * (NC_MAX_NAME + 1));;
status = nc_inq_dimname(ncid, janm, tmp_value);
status = get_dimension(ncid, tmp_value, dim_length);
free(tmp_value);
tmp_value = nullptr;
}
}
return status;
}
Expand Down

0 comments on commit 33d1a7c

Please sign in to comment.