Fossil SCM

Changes to the file_getcwd() routine to avoid a false-positive compiler warning from gcc 10.2.1.

drh 2022-06-23 12:44 trunk
Commit 85b83206f42cb64b5699a721c67e12821d4502782ac57fa8f1bfd09cd78ce551
1 file changed +3 -4
+3 -4
--- src/file.c
+++ src/file.c
@@ -1192,14 +1192,13 @@
11921192
**
11931193
** Store the value of the CWD in zBuf which is nBuf bytes in size.
11941194
** or if zBuf==0, allocate space to hold the result using fossil_malloc().
11951195
*/
11961196
char *file_getcwd(char *zBuf, int nBuf){
1197
- char zTemp[2000];
11981197
if( zBuf==0 ){
1199
- zBuf = zTemp;
1200
- nBuf = sizeof(zTemp);
1198
+ char zTemp[2000];
1199
+ return fossil_strdup(file_getcwd(zTemp, sizeof(zTemp)));
12011200
}
12021201
#ifdef _WIN32
12031202
win32_getcwd(zBuf, nBuf);
12041203
#else
12051204
if( getcwd(zBuf, nBuf-1)==0 ){
@@ -1209,11 +1208,11 @@
12091208
fossil_fatal("cannot find current working directory; %s",
12101209
strerror(errno));
12111210
}
12121211
}
12131212
#endif
1214
- return zBuf==zTemp ? fossil_strdup(zBuf) : zBuf;
1213
+ return zBuf;
12151214
}
12161215
12171216
/*
12181217
** Return true if zPath is an absolute pathname. Return false
12191218
** if it is relative.
12201219
--- src/file.c
+++ src/file.c
@@ -1192,14 +1192,13 @@
1192 **
1193 ** Store the value of the CWD in zBuf which is nBuf bytes in size.
1194 ** or if zBuf==0, allocate space to hold the result using fossil_malloc().
1195 */
1196 char *file_getcwd(char *zBuf, int nBuf){
1197 char zTemp[2000];
1198 if( zBuf==0 ){
1199 zBuf = zTemp;
1200 nBuf = sizeof(zTemp);
1201 }
1202 #ifdef _WIN32
1203 win32_getcwd(zBuf, nBuf);
1204 #else
1205 if( getcwd(zBuf, nBuf-1)==0 ){
@@ -1209,11 +1208,11 @@
1209 fossil_fatal("cannot find current working directory; %s",
1210 strerror(errno));
1211 }
1212 }
1213 #endif
1214 return zBuf==zTemp ? fossil_strdup(zBuf) : zBuf;
1215 }
1216
1217 /*
1218 ** Return true if zPath is an absolute pathname. Return false
1219 ** if it is relative.
1220
--- src/file.c
+++ src/file.c
@@ -1192,14 +1192,13 @@
1192 **
1193 ** Store the value of the CWD in zBuf which is nBuf bytes in size.
1194 ** or if zBuf==0, allocate space to hold the result using fossil_malloc().
1195 */
1196 char *file_getcwd(char *zBuf, int nBuf){
 
1197 if( zBuf==0 ){
1198 char zTemp[2000];
1199 return fossil_strdup(file_getcwd(zTemp, sizeof(zTemp)));
1200 }
1201 #ifdef _WIN32
1202 win32_getcwd(zBuf, nBuf);
1203 #else
1204 if( getcwd(zBuf, nBuf-1)==0 ){
@@ -1209,11 +1208,11 @@
1208 fossil_fatal("cannot find current working directory; %s",
1209 strerror(errno));
1210 }
1211 }
1212 #endif
1213 return zBuf;
1214 }
1215
1216 /*
1217 ** Return true if zPath is an absolute pathname. Return false
1218 ** if it is relative.
1219

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button