@@ -42,7 +42,15 @@ extern "C"
42
42
QString GRASS_EXPORT QgsGrass::shortPath ( const QString &path )
43
43
{
44
44
TCHAR buf[MAX_PATH];
45
- GetShortPathName ( path.toUtf8 ().constData (), buf, MAX_PATH );
45
+ int len = GetShortPathName ( path.toUtf8 ().constData (), buf, MAX_PATH );
46
+
47
+ if ( len == 0 || len > MAX_PATH )
48
+ {
49
+ QgsDebugMsg ( QString ( " GetShortPathName('%1') failed with %2: %3" )
50
+ .arg ( path ).arg ( len ).arg ( GetLastError () ) );
51
+ return path;
52
+ }
53
+
46
54
QString res = QString::fromUtf8 ( buf );
47
55
return res;
48
56
}
@@ -173,7 +181,7 @@ void GRASS_EXPORT QgsGrass::init( void )
173
181
QgsDebugMsg ( QString ( " Valid GRASS gisBase is: %1" ).arg ( gisBase ) );
174
182
QString gisBaseEnv = " GISBASE=" + gisBase;
175
183
/* _Correct_ putenv() implementation is not making copy! */
176
- char *gisBaseEnvChar = new char [gisBaseEnv.length ()+1 ];
184
+ char *gisBaseEnvChar = new char [gisBaseEnv.toUtf8 (). length ()+1 ];
177
185
strcpy ( gisBaseEnvChar, gisBaseEnv.toUtf8 ().constData () );
178
186
putenv ( gisBaseEnvChar );
179
187
@@ -198,14 +206,15 @@ void GRASS_EXPORT QgsGrass::init( void )
198
206
199
207
// Add path to MSYS bin
200
208
// Warning: MSYS sh.exe will translate this path to '/bin'
201
- path.append ( sep + shortPath ( QCoreApplication::applicationDirPath () + " /msys/bin/" ) );
209
+ if ( QFileInfo ( QCoreApplication::applicationDirPath () + " /msys/bin/" ).isDir () )
210
+ path.append ( sep + shortPath ( QCoreApplication::applicationDirPath () + " /msys/bin/" ) );
202
211
#endif
203
212
204
213
QString p = getenv ( " PATH" );
205
214
path.append ( sep + p );
206
215
207
216
QgsDebugMsg ( QString ( " set PATH: %1" ).arg ( path ) );
208
- char *pathEnvChar = new char [path.length ()+1 ];
217
+ char *pathEnvChar = new char [path.toUtf8 (). length ()+1 ];
209
218
strcpy ( pathEnvChar, path.toUtf8 ().constData () );
210
219
putenv ( pathEnvChar );
211
220
@@ -214,7 +223,7 @@ void GRASS_EXPORT QgsGrass::init( void )
214
223
QString pp = getenv ( " PATH" );
215
224
pythonpath.append ( sep + pp );
216
225
QgsDebugMsg ( QString ( " set PYTHONPATH: %1" ).arg ( pythonpath ) );
217
- char *pythonpathEnvChar = new char [pythonpath.length ()+1 ];
226
+ char *pythonpathEnvChar = new char [pythonpath.toUtf8 (). length ()+1 ];
218
227
strcpy ( pythonpathEnvChar, pythonpath.toUtf8 ().constData () );
219
228
putenv ( pythonpathEnvChar );
220
229
0 commit comments