1515#include " gdal.h"
1616#include " gdalgetgdalpath.h"
1717
18+ #include < cassert>
19+
1820/* ***********************************************************************/
1921/* GDALGetGDALPath() */
2022/* ***********************************************************************/
@@ -38,7 +40,7 @@ std::string GDALGetGDALPath()
3840#endif
3941 })
4042 {
41- const std::string osPath =
43+ std::string osPath =
4244 CPLFormFilenameSafe (pszGDAL_PATH, pszProgramName, nullptr );
4345 if (VSIStatL (osPath.c_str (), &sStat ) == 0 )
4446 return osPath;
@@ -83,7 +85,7 @@ std::string GDALGetGDALPath()
8385 if (VSIStatL (osBinFilename.c_str (), &sStat ) == 0 )
8486 {
8587 // Case if pszLibName=/usr/lib/libgdal.so.xxx
86- osPath = osBinFilename;
88+ osPath = std::move ( osBinFilename) ;
8789 }
8890 else
8991 {
@@ -96,7 +98,7 @@ std::string GDALGetGDALPath()
9698 if (VSIStatL (osBinFilename.c_str (), &sStat ) == 0 )
9799 {
98100 // Case if pszLibName=/usr/lib/yyyyy/libgdal.so.xxx
99- osPath = osBinFilename;
101+ osPath = std::move ( osBinFilename) ;
100102 }
101103 else
102104 {
@@ -105,7 +107,7 @@ std::string GDALGetGDALPath()
105107 if (VSIStatL (osBinFilename.c_str (), &sStat ) == 0 )
106108 {
107109 // Case if pszLibName=/path/to/build_dir/libgdal.so.xxx
108- osPath = osBinFilename;
110+ osPath = std::move ( osBinFilename) ;
109111 }
110112 }
111113 }
@@ -145,7 +147,7 @@ std::string GDALGetGDALPath()
145147 fpOut->Read (szVersion, 1 , nVersionSize);
146148 for (const char ch : {' \n ' , ' \r ' })
147149 {
148- if (szVersion[nVersionSize - 1 ] == ch)
150+ if (nVersionSize >= 1 && szVersion[nVersionSize - 1 ] == ch)
149151 {
150152 szVersion[nVersionSize - 1 ] = 0 ;
151153 --nVersionSize;
0 commit comments