Fossil SCM

Fix some compiler warnings 'may be uninitialized in this function'. Move path conversions out of win32_chdir/win32_access/win32_stat, as its caller already can do that. This eliminates some code duplication.

jan.nijtmans 2014-04-29 10:19 trunk
Commit 503482a2c65b3b97fddd035109bc2cdcdbb7040d
3 files changed +15 -13 +5 -5 +8 -16
+15 -13
--- src/file.c
+++ src/file.c
@@ -79,23 +79,23 @@
7979
** Fill stat buf with information received from stat() or lstat().
8080
** lstat() is called on Unix if isWd is TRUE and allow-symlinks setting is on.
8181
**
8282
*/
8383
static int fossil_stat(const char *zFilename, struct fossilStat *buf, int isWd){
84
-#if !defined(_WIN32)
8584
int rc;
86
- char *zMbcs = fossil_utf8_to_filename(zFilename);
85
+ void *zMbcs = fossil_utf8_to_filename(zFilename);
86
+#if !defined(_WIN32)
8787
if( isWd && g.allowSymlinks ){
8888
rc = lstat(zMbcs, buf);
8989
}else{
9090
rc = stat(zMbcs, buf);
9191
}
92
+#else
93
+ rc = win32_stat(zMbcs, buf, isWd);
94
+#endif
9295
fossil_filename_free(zMbcs);
9396
return rc;
94
-#else
95
- return win32_stat(zFilename, buf, isWd);
96
-#endif
9797
}
9898
9999
/*
100100
** Fill in the fileStat variable for the file named zFilename.
101101
** If zFilename==0, then use the previous value of fileStat if
@@ -316,38 +316,40 @@
316316
317317
/*
318318
** Wrapper around the access() system call.
319319
*/
320320
int file_access(const char *zFilename, int flags){
321
+ int rc;
322
+ void *zMbcs = fossil_utf8_to_filename(zFilename);
321323
#ifdef _WIN32
322
- return win32_access(zFilename, flags);
324
+ rc = win32_access(zMbcs, flags);
323325
#else
324
- char *zMbcs = fossil_utf8_to_filename(zFilename);
325
- int rc = access(zMbcs, flags);
326
+ rc = access(zMbcs, flags);
327
+#endif
326328
fossil_filename_free(zMbcs);
327329
return rc;
328
-#endif
329330
}
330331
331332
/*
332333
** Wrapper around the chdir() system call.
333334
** If bChroot=1, do a chroot to this dir as well
334335
** (UNIX only)
335336
*/
336337
int file_chdir(const char *zChDir, int bChroot){
338
+ int rc;
339
+ void *zPath = fossil_utf8_to_filename(zChDir);
337340
#ifdef _WIN32
338
- return win32_chdir(zChDir, bChroot);
341
+ rc = win32_chdir(zPath, bChroot);
339342
#else
340
- char *zPath = fossil_utf8_to_filename(zChDir);
341
- int rc = chdir(zPath);
343
+ rc = chdir(zPath);
342344
if( !rc && bChroot ){
343345
rc = chroot(zPath);
344346
if( !rc ) rc = chdir("/");
345347
}
348
+#endif
346349
fossil_filename_free(zPath);
347350
return rc;
348
-#endif
349351
}
350352
351353
/*
352354
** Find an unused filename similar to zBase with zSuffix appended.
353355
**
354356
--- src/file.c
+++ src/file.c
@@ -79,23 +79,23 @@
79 ** Fill stat buf with information received from stat() or lstat().
80 ** lstat() is called on Unix if isWd is TRUE and allow-symlinks setting is on.
81 **
82 */
83 static int fossil_stat(const char *zFilename, struct fossilStat *buf, int isWd){
84 #if !defined(_WIN32)
85 int rc;
86 char *zMbcs = fossil_utf8_to_filename(zFilename);
 
87 if( isWd && g.allowSymlinks ){
88 rc = lstat(zMbcs, buf);
89 }else{
90 rc = stat(zMbcs, buf);
91 }
 
 
 
92 fossil_filename_free(zMbcs);
93 return rc;
94 #else
95 return win32_stat(zFilename, buf, isWd);
96 #endif
97 }
98
99 /*
100 ** Fill in the fileStat variable for the file named zFilename.
101 ** If zFilename==0, then use the previous value of fileStat if
@@ -316,38 +316,40 @@
316
317 /*
318 ** Wrapper around the access() system call.
319 */
320 int file_access(const char *zFilename, int flags){
 
 
321 #ifdef _WIN32
322 return win32_access(zFilename, flags);
323 #else
324 char *zMbcs = fossil_utf8_to_filename(zFilename);
325 int rc = access(zMbcs, flags);
326 fossil_filename_free(zMbcs);
327 return rc;
328 #endif
329 }
330
331 /*
332 ** Wrapper around the chdir() system call.
333 ** If bChroot=1, do a chroot to this dir as well
334 ** (UNIX only)
335 */
336 int file_chdir(const char *zChDir, int bChroot){
 
 
337 #ifdef _WIN32
338 return win32_chdir(zChDir, bChroot);
339 #else
340 char *zPath = fossil_utf8_to_filename(zChDir);
341 int rc = chdir(zPath);
342 if( !rc && bChroot ){
343 rc = chroot(zPath);
344 if( !rc ) rc = chdir("/");
345 }
 
346 fossil_filename_free(zPath);
347 return rc;
348 #endif
349 }
350
351 /*
352 ** Find an unused filename similar to zBase with zSuffix appended.
353 **
354
--- src/file.c
+++ src/file.c
@@ -79,23 +79,23 @@
79 ** Fill stat buf with information received from stat() or lstat().
80 ** lstat() is called on Unix if isWd is TRUE and allow-symlinks setting is on.
81 **
82 */
83 static int fossil_stat(const char *zFilename, struct fossilStat *buf, int isWd){
 
84 int rc;
85 void *zMbcs = fossil_utf8_to_filename(zFilename);
86 #if !defined(_WIN32)
87 if( isWd && g.allowSymlinks ){
88 rc = lstat(zMbcs, buf);
89 }else{
90 rc = stat(zMbcs, buf);
91 }
92 #else
93 rc = win32_stat(zMbcs, buf, isWd);
94 #endif
95 fossil_filename_free(zMbcs);
96 return rc;
 
 
 
97 }
98
99 /*
100 ** Fill in the fileStat variable for the file named zFilename.
101 ** If zFilename==0, then use the previous value of fileStat if
@@ -316,38 +316,40 @@
316
317 /*
318 ** Wrapper around the access() system call.
319 */
320 int file_access(const char *zFilename, int flags){
321 int rc;
322 void *zMbcs = fossil_utf8_to_filename(zFilename);
323 #ifdef _WIN32
324 rc = win32_access(zMbcs, flags);
325 #else
326 rc = access(zMbcs, flags);
327 #endif
328 fossil_filename_free(zMbcs);
329 return rc;
 
330 }
331
332 /*
333 ** Wrapper around the chdir() system call.
334 ** If bChroot=1, do a chroot to this dir as well
335 ** (UNIX only)
336 */
337 int file_chdir(const char *zChDir, int bChroot){
338 int rc;
339 void *zPath = fossil_utf8_to_filename(zChDir);
340 #ifdef _WIN32
341 rc = win32_chdir(zPath, bChroot);
342 #else
343 rc = chdir(zPath);
 
344 if( !rc && bChroot ){
345 rc = chroot(zPath);
346 if( !rc ) rc = chdir("/");
347 }
348 #endif
349 fossil_filename_free(zPath);
350 return rc;
 
351 }
352
353 /*
354 ** Find an unused filename similar to zBase with zSuffix appended.
355 **
356
+5 -5
--- src/lookslike.c
+++ src/lookslike.c
@@ -371,15 +371,15 @@
371371
**
372372
** FILENAME is the name of a file to check for textual content in the UTF-8
373373
** and/or UTF-16 encodings.
374374
*/
375375
void looks_like_utf_test_cmd(void){
376
- Blob blob; /* the contents of the specified file */
377
- int fUtf8; /* return value of starts_with_utf8_bom() */
378
- int fUtf16; /* return value of starts_with_utf16_bom() */
379
- int fUnicode; /* return value of could_be_utf16() */
380
- int lookFlags; /* output flags from looks_like_utf8/utf16() */
376
+ Blob blob; /* the contents of the specified file */
377
+ int fUtf8 = 0; /* return value of starts_with_utf8_bom() */
378
+ int fUtf16 = 0; /* return value of starts_with_utf16_bom() */
379
+ int fUnicode = 0; /* return value of could_be_utf16() */
380
+ int lookFlags = 0; /* output flags from looks_like_utf8/utf16() */
381381
int bRevUtf16 = 0; /* non-zero -> UTF-16 byte order reversed */
382382
int fForceUtf8 = find_option("utf8",0,0)!=0;
383383
int fForceUtf16 = find_option("utf16",0,0)!=0;
384384
const char *zCount = find_option("limit","n",1);
385385
int nRepeat = 1;
386386
--- src/lookslike.c
+++ src/lookslike.c
@@ -371,15 +371,15 @@
371 **
372 ** FILENAME is the name of a file to check for textual content in the UTF-8
373 ** and/or UTF-16 encodings.
374 */
375 void looks_like_utf_test_cmd(void){
376 Blob blob; /* the contents of the specified file */
377 int fUtf8; /* return value of starts_with_utf8_bom() */
378 int fUtf16; /* return value of starts_with_utf16_bom() */
379 int fUnicode; /* return value of could_be_utf16() */
380 int lookFlags; /* output flags from looks_like_utf8/utf16() */
381 int bRevUtf16 = 0; /* non-zero -> UTF-16 byte order reversed */
382 int fForceUtf8 = find_option("utf8",0,0)!=0;
383 int fForceUtf16 = find_option("utf16",0,0)!=0;
384 const char *zCount = find_option("limit","n",1);
385 int nRepeat = 1;
386
--- src/lookslike.c
+++ src/lookslike.c
@@ -371,15 +371,15 @@
371 **
372 ** FILENAME is the name of a file to check for textual content in the UTF-8
373 ** and/or UTF-16 encodings.
374 */
375 void looks_like_utf_test_cmd(void){
376 Blob blob; /* the contents of the specified file */
377 int fUtf8 = 0; /* return value of starts_with_utf8_bom() */
378 int fUtf16 = 0; /* return value of starts_with_utf16_bom() */
379 int fUnicode = 0; /* return value of could_be_utf16() */
380 int lookFlags = 0; /* output flags from looks_like_utf8/utf16() */
381 int bRevUtf16 = 0; /* non-zero -> UTF-16 byte order reversed */
382 int fForceUtf8 = find_option("utf8",0,0)!=0;
383 int fForceUtf16 = find_option("utf16",0,0)!=0;
384 const char *zCount = find_option("limit","n",1);
385 int nRepeat = 1;
386
+8 -16
--- src/winfile.c
+++ src/winfile.c
@@ -32,15 +32,13 @@
3232
/*
3333
** Fill stat buf with information received from stat() or lstat().
3434
** lstat() is called on Unix if isWd is TRUE and allow-symlinks setting is on.
3535
**
3636
*/
37
-int win32_stat(const char *zFilename, struct fossilStat *buf, int isWd){
37
+int win32_stat(const wchar_t *zFilename, struct fossilStat *buf, int isWd){
3838
WIN32_FILE_ATTRIBUTE_DATA attr;
39
- wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
40
- int rc = GetFileAttributesExW(zMbcs, GetFileExInfoStandard, &attr);
41
- fossil_filename_free(zMbcs);
39
+ int rc = GetFileAttributesExW(zFilename, GetFileExInfoStandard, &attr);
4240
if( rc ){
4341
ULARGE_INTEGER ull;
4442
ull.LowPart = attr.ftLastWriteTime.dwLowDateTime;
4543
ull.HighPart = attr.ftLastWriteTime.dwHighDateTime;
4644
buf->st_mode = (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ?
@@ -53,11 +51,11 @@
5351
5452
/*
5553
** Wrapper around the access() system call. This code was copied from Tcl
5654
** 8.6 and then modified.
5755
*/
58
-int win32_access(const char *zFilename, int flags){
56
+int win32_access(const wchar_t *zFilename, int flags){
5957
int rc = 0;
6058
PSECURITY_DESCRIPTOR pSd = NULL;
6159
unsigned long size;
6260
PSID pSid = NULL;
6361
BOOL sidDefaulted;
@@ -67,12 +65,11 @@
6765
HANDLE hToken = NULL;
6866
DWORD desiredAccess = 0, grantedAccess = 0;
6967
BOOL accessYesNo = FALSE;
7068
PRIVILEGE_SET privSet;
7169
DWORD privSetSize = sizeof(PRIVILEGE_SET);
72
- wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
73
- DWORD attr = GetFileAttributesW(zMbcs);
70
+ DWORD attr = GetFileAttributesW(zFilename);
7471
7572
if( attr==INVALID_FILE_ATTRIBUTES ){
7673
/*
7774
* File might not exist.
7875
*/
@@ -114,11 +111,11 @@
114111
/*
115112
* First find out how big the buffer needs to be.
116113
*/
117114
118115
size = 0;
119
- GetFileSecurityW(zMbcs,
116
+ GetFileSecurityW(zFilename,
120117
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
121118
DACL_SECURITY_INFORMATION | LABEL_SECURITY_INFORMATION,
122119
0, 0, &size);
123120
124121
/*
@@ -146,11 +143,11 @@
146143
147144
/*
148145
* Call GetFileSecurity() for real.
149146
*/
150147
151
- if( !GetFileSecurityW(zMbcs,
148
+ if( !GetFileSecurityW(zFilename,
152149
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
153150
DACL_SECURITY_INFORMATION | LABEL_SECURITY_INFORMATION,
154151
pSd, size, &size) ){
155152
/*
156153
* Error getting owner SD
@@ -243,23 +240,18 @@
243240
impersonated = FALSE;
244241
}
245242
if( pSd!=NULL ){
246243
HeapFree(GetProcessHeap(), 0, pSd);
247244
}
248
- fossil_filename_free(zMbcs);
249245
return rc;
250246
}
251247
252248
/*
253249
** Wrapper around the chdir() system call.
254
-** If bChroot=1, do a chroot to this dir as well
255
-** (UNIX only)
256250
*/
257
-int win32_chdir(const char *zChDir, int bChroot){
258
- wchar_t *zPath = fossil_utf8_to_filename(zChDir);
259
- int rc = (int)!SetCurrentDirectoryW(zPath);
260
- fossil_filename_free(zPath);
251
+int win32_chdir(const void *zChDir, int bChroot){
252
+ int rc = (int)!SetCurrentDirectoryW(zChDir);
261253
return rc;
262254
}
263255
264256
/*
265257
** Get the current working directory.
266258
--- src/winfile.c
+++ src/winfile.c
@@ -32,15 +32,13 @@
32 /*
33 ** Fill stat buf with information received from stat() or lstat().
34 ** lstat() is called on Unix if isWd is TRUE and allow-symlinks setting is on.
35 **
36 */
37 int win32_stat(const char *zFilename, struct fossilStat *buf, int isWd){
38 WIN32_FILE_ATTRIBUTE_DATA attr;
39 wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
40 int rc = GetFileAttributesExW(zMbcs, GetFileExInfoStandard, &attr);
41 fossil_filename_free(zMbcs);
42 if( rc ){
43 ULARGE_INTEGER ull;
44 ull.LowPart = attr.ftLastWriteTime.dwLowDateTime;
45 ull.HighPart = attr.ftLastWriteTime.dwHighDateTime;
46 buf->st_mode = (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ?
@@ -53,11 +51,11 @@
53
54 /*
55 ** Wrapper around the access() system call. This code was copied from Tcl
56 ** 8.6 and then modified.
57 */
58 int win32_access(const char *zFilename, int flags){
59 int rc = 0;
60 PSECURITY_DESCRIPTOR pSd = NULL;
61 unsigned long size;
62 PSID pSid = NULL;
63 BOOL sidDefaulted;
@@ -67,12 +65,11 @@
67 HANDLE hToken = NULL;
68 DWORD desiredAccess = 0, grantedAccess = 0;
69 BOOL accessYesNo = FALSE;
70 PRIVILEGE_SET privSet;
71 DWORD privSetSize = sizeof(PRIVILEGE_SET);
72 wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
73 DWORD attr = GetFileAttributesW(zMbcs);
74
75 if( attr==INVALID_FILE_ATTRIBUTES ){
76 /*
77 * File might not exist.
78 */
@@ -114,11 +111,11 @@
114 /*
115 * First find out how big the buffer needs to be.
116 */
117
118 size = 0;
119 GetFileSecurityW(zMbcs,
120 OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
121 DACL_SECURITY_INFORMATION | LABEL_SECURITY_INFORMATION,
122 0, 0, &size);
123
124 /*
@@ -146,11 +143,11 @@
146
147 /*
148 * Call GetFileSecurity() for real.
149 */
150
151 if( !GetFileSecurityW(zMbcs,
152 OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
153 DACL_SECURITY_INFORMATION | LABEL_SECURITY_INFORMATION,
154 pSd, size, &size) ){
155 /*
156 * Error getting owner SD
@@ -243,23 +240,18 @@
243 impersonated = FALSE;
244 }
245 if( pSd!=NULL ){
246 HeapFree(GetProcessHeap(), 0, pSd);
247 }
248 fossil_filename_free(zMbcs);
249 return rc;
250 }
251
252 /*
253 ** Wrapper around the chdir() system call.
254 ** If bChroot=1, do a chroot to this dir as well
255 ** (UNIX only)
256 */
257 int win32_chdir(const char *zChDir, int bChroot){
258 wchar_t *zPath = fossil_utf8_to_filename(zChDir);
259 int rc = (int)!SetCurrentDirectoryW(zPath);
260 fossil_filename_free(zPath);
261 return rc;
262 }
263
264 /*
265 ** Get the current working directory.
266
--- src/winfile.c
+++ src/winfile.c
@@ -32,15 +32,13 @@
32 /*
33 ** Fill stat buf with information received from stat() or lstat().
34 ** lstat() is called on Unix if isWd is TRUE and allow-symlinks setting is on.
35 **
36 */
37 int win32_stat(const wchar_t *zFilename, struct fossilStat *buf, int isWd){
38 WIN32_FILE_ATTRIBUTE_DATA attr;
39 int rc = GetFileAttributesExW(zFilename, GetFileExInfoStandard, &attr);
 
 
40 if( rc ){
41 ULARGE_INTEGER ull;
42 ull.LowPart = attr.ftLastWriteTime.dwLowDateTime;
43 ull.HighPart = attr.ftLastWriteTime.dwHighDateTime;
44 buf->st_mode = (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ?
@@ -53,11 +51,11 @@
51
52 /*
53 ** Wrapper around the access() system call. This code was copied from Tcl
54 ** 8.6 and then modified.
55 */
56 int win32_access(const wchar_t *zFilename, int flags){
57 int rc = 0;
58 PSECURITY_DESCRIPTOR pSd = NULL;
59 unsigned long size;
60 PSID pSid = NULL;
61 BOOL sidDefaulted;
@@ -67,12 +65,11 @@
65 HANDLE hToken = NULL;
66 DWORD desiredAccess = 0, grantedAccess = 0;
67 BOOL accessYesNo = FALSE;
68 PRIVILEGE_SET privSet;
69 DWORD privSetSize = sizeof(PRIVILEGE_SET);
70 DWORD attr = GetFileAttributesW(zFilename);
 
71
72 if( attr==INVALID_FILE_ATTRIBUTES ){
73 /*
74 * File might not exist.
75 */
@@ -114,11 +111,11 @@
111 /*
112 * First find out how big the buffer needs to be.
113 */
114
115 size = 0;
116 GetFileSecurityW(zFilename,
117 OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
118 DACL_SECURITY_INFORMATION | LABEL_SECURITY_INFORMATION,
119 0, 0, &size);
120
121 /*
@@ -146,11 +143,11 @@
143
144 /*
145 * Call GetFileSecurity() for real.
146 */
147
148 if( !GetFileSecurityW(zFilename,
149 OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
150 DACL_SECURITY_INFORMATION | LABEL_SECURITY_INFORMATION,
151 pSd, size, &size) ){
152 /*
153 * Error getting owner SD
@@ -243,23 +240,18 @@
240 impersonated = FALSE;
241 }
242 if( pSd!=NULL ){
243 HeapFree(GetProcessHeap(), 0, pSd);
244 }
 
245 return rc;
246 }
247
248 /*
249 ** Wrapper around the chdir() system call.
 
 
250 */
251 int win32_chdir(const void *zChDir, int bChroot){
252 int rc = (int)!SetCurrentDirectoryW(zChDir);
 
 
253 return rc;
254 }
255
256 /*
257 ** Get the current working directory.
258

Keyboard Shortcuts

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