Fossil SCM

Mark functions that never return (ex: fossil_panic()) as such so that static analyzers can do a better job of pruning paths.

drh 2011-10-15 12:16 trunk
Commit 86d2b4efc8367e5300baa613ef13d092cc48927b
3 files changed +4 -4 +9 +4 -4
+4 -4
--- src/cgi.c
+++ src/cgi.c
@@ -362,11 +362,11 @@
362362
/*
363363
** Do a redirect request to the URL given in the argument.
364364
**
365365
** The URL must be relative to the base of the fossil server.
366366
*/
367
-void cgi_redirect(const char *zURL){
367
+NORETURN void cgi_redirect(const char *zURL){
368368
char *zLocation;
369369
CGIDEBUG(("redirect to %s\n", zURL));
370370
if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 ){
371371
zLocation = mprintf("Location: %s\r\n", zURL);
372372
}else if( *zURL=='/' ){
@@ -381,11 +381,11 @@
381381
cgi_set_status(302, "Moved Temporarily");
382382
free(zLocation);
383383
cgi_reply();
384384
fossil_exit(0);
385385
}
386
-void cgi_redirectf(const char *zFormat, ...){
386
+NORETURN void cgi_redirectf(const char *zFormat, ...){
387387
va_list ap;
388388
va_start(ap, zFormat);
389389
cgi_redirect(vmprintf(zFormat, ap));
390390
va_end(ap);
391391
}
@@ -927,11 +927,11 @@
927927
928928
929929
/*
930930
** Send a reply indicating that the HTTP request was malformed
931931
*/
932
-static void malformed_request(void){
932
+static NORETURN void malformed_request(void){
933933
cgi_set_status(501, "Not Implemented");
934934
cgi_printf(
935935
"<html><body>Unrecognized HTTP Request</body></html>\n"
936936
);
937937
cgi_reply();
@@ -939,11 +939,11 @@
939939
}
940940
941941
/*
942942
** Panic and die while processing a webpage.
943943
*/
944
-void cgi_panic(const char *zFormat, ...){
944
+NORETURN void cgi_panic(const char *zFormat, ...){
945945
va_list ap;
946946
cgi_reset_content();
947947
cgi_set_status(500, "Internal Server Error");
948948
cgi_printf(
949949
"<html><body><h1>Internal Server Error</h1>\n"
950950
--- src/cgi.c
+++ src/cgi.c
@@ -362,11 +362,11 @@
362 /*
363 ** Do a redirect request to the URL given in the argument.
364 **
365 ** The URL must be relative to the base of the fossil server.
366 */
367 void cgi_redirect(const char *zURL){
368 char *zLocation;
369 CGIDEBUG(("redirect to %s\n", zURL));
370 if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 ){
371 zLocation = mprintf("Location: %s\r\n", zURL);
372 }else if( *zURL=='/' ){
@@ -381,11 +381,11 @@
381 cgi_set_status(302, "Moved Temporarily");
382 free(zLocation);
383 cgi_reply();
384 fossil_exit(0);
385 }
386 void cgi_redirectf(const char *zFormat, ...){
387 va_list ap;
388 va_start(ap, zFormat);
389 cgi_redirect(vmprintf(zFormat, ap));
390 va_end(ap);
391 }
@@ -927,11 +927,11 @@
927
928
929 /*
930 ** Send a reply indicating that the HTTP request was malformed
931 */
932 static void malformed_request(void){
933 cgi_set_status(501, "Not Implemented");
934 cgi_printf(
935 "<html><body>Unrecognized HTTP Request</body></html>\n"
936 );
937 cgi_reply();
@@ -939,11 +939,11 @@
939 }
940
941 /*
942 ** Panic and die while processing a webpage.
943 */
944 void cgi_panic(const char *zFormat, ...){
945 va_list ap;
946 cgi_reset_content();
947 cgi_set_status(500, "Internal Server Error");
948 cgi_printf(
949 "<html><body><h1>Internal Server Error</h1>\n"
950
--- src/cgi.c
+++ src/cgi.c
@@ -362,11 +362,11 @@
362 /*
363 ** Do a redirect request to the URL given in the argument.
364 **
365 ** The URL must be relative to the base of the fossil server.
366 */
367 NORETURN void cgi_redirect(const char *zURL){
368 char *zLocation;
369 CGIDEBUG(("redirect to %s\n", zURL));
370 if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 ){
371 zLocation = mprintf("Location: %s\r\n", zURL);
372 }else if( *zURL=='/' ){
@@ -381,11 +381,11 @@
381 cgi_set_status(302, "Moved Temporarily");
382 free(zLocation);
383 cgi_reply();
384 fossil_exit(0);
385 }
386 NORETURN void cgi_redirectf(const char *zFormat, ...){
387 va_list ap;
388 va_start(ap, zFormat);
389 cgi_redirect(vmprintf(zFormat, ap));
390 va_end(ap);
391 }
@@ -927,11 +927,11 @@
927
928
929 /*
930 ** Send a reply indicating that the HTTP request was malformed
931 */
932 static NORETURN void malformed_request(void){
933 cgi_set_status(501, "Not Implemented");
934 cgi_printf(
935 "<html><body>Unrecognized HTTP Request</body></html>\n"
936 );
937 cgi_reply();
@@ -939,11 +939,11 @@
939 }
940
941 /*
942 ** Panic and die while processing a webpage.
943 */
944 NORETURN void cgi_panic(const char *zFormat, ...){
945 va_list ap;
946 cgi_reset_content();
947 cgi_set_status(500, "Internal Server Error");
948 cgi_printf(
949 "<html><body><h1>Internal Server Error</h1>\n"
950
--- src/config.h
+++ src/config.h
@@ -134,6 +134,15 @@
134134
#else /* Generates a warning - but it always works */
135135
# define FOSSIL_INT_TO_PTR(X) ((void*)(X))
136136
# define FOSSIL_PTR_TO_INT(X) ((int)(X))
137137
#endif
138138
139
+/*
140
+** A marker for functions that never return.
141
+*/
142
+#if defined(__GNUC__) || defined(__clang__)
143
+# define NORETURN __attribute__((__noreturn__))
144
+#else
145
+# define NORETURN
146
+#endif
147
+
139148
#endif /* _RC_COMPILE_ */
140149
--- src/config.h
+++ src/config.h
@@ -134,6 +134,15 @@
134 #else /* Generates a warning - but it always works */
135 # define FOSSIL_INT_TO_PTR(X) ((void*)(X))
136 # define FOSSIL_PTR_TO_INT(X) ((int)(X))
137 #endif
138
 
 
 
 
 
 
 
 
 
139 #endif /* _RC_COMPILE_ */
140
--- src/config.h
+++ src/config.h
@@ -134,6 +134,15 @@
134 #else /* Generates a warning - but it always works */
135 # define FOSSIL_INT_TO_PTR(X) ((void*)(X))
136 # define FOSSIL_PTR_TO_INT(X) ((int)(X))
137 #endif
138
139 /*
140 ** A marker for functions that never return.
141 */
142 #if defined(__GNUC__) || defined(__clang__)
143 # define NORETURN __attribute__((__noreturn__))
144 #else
145 # define NORETURN
146 #endif
147
148 #endif /* _RC_COMPILE_ */
149
+4 -4
--- src/main.c
+++ src/main.c
@@ -400,20 +400,20 @@
400400
}
401401
402402
/*
403403
** Exit. Take care to close the database first.
404404
*/
405
-void fossil_exit(int rc){
405
+NORETURN void fossil_exit(int rc){
406406
db_close(1);
407407
exit(rc);
408408
}
409409
410410
/*
411411
** Print an error message, rollback all databases, and quit. These
412412
** routines never return.
413413
*/
414
-void fossil_panic(const char *zFormat, ...){
414
+NORETURN void fossil_panic(const char *zFormat, ...){
415415
char *z;
416416
va_list ap;
417417
static int once = 1;
418418
mainInFatalError = 1;
419419
va_start(ap, zFormat);
@@ -428,11 +428,11 @@
428428
fossil_puts(zOut, 1);
429429
}
430430
db_force_rollback();
431431
fossil_exit(1);
432432
}
433
-void fossil_fatal(const char *zFormat, ...){
433
+NORETURN void fossil_fatal(const char *zFormat, ...){
434434
char *z;
435435
va_list ap;
436436
mainInFatalError = 1;
437437
va_start(ap, zFormat);
438438
z = vmprintf(zFormat, ap);
@@ -916,11 +916,11 @@
916916
}
917917
918918
/*
919919
** Send an HTTP redirect back to the designated Index Page.
920920
*/
921
-void fossil_redirect_home(void){
921
+NORETURN void fossil_redirect_home(void){
922922
cgi_redirectf("%s%s", g.zTop, db_get("index-page", "/index"));
923923
}
924924
925925
/*
926926
** If running as root, chroot to the directory containing the
927927
--- src/main.c
+++ src/main.c
@@ -400,20 +400,20 @@
400 }
401
402 /*
403 ** Exit. Take care to close the database first.
404 */
405 void fossil_exit(int rc){
406 db_close(1);
407 exit(rc);
408 }
409
410 /*
411 ** Print an error message, rollback all databases, and quit. These
412 ** routines never return.
413 */
414 void fossil_panic(const char *zFormat, ...){
415 char *z;
416 va_list ap;
417 static int once = 1;
418 mainInFatalError = 1;
419 va_start(ap, zFormat);
@@ -428,11 +428,11 @@
428 fossil_puts(zOut, 1);
429 }
430 db_force_rollback();
431 fossil_exit(1);
432 }
433 void fossil_fatal(const char *zFormat, ...){
434 char *z;
435 va_list ap;
436 mainInFatalError = 1;
437 va_start(ap, zFormat);
438 z = vmprintf(zFormat, ap);
@@ -916,11 +916,11 @@
916 }
917
918 /*
919 ** Send an HTTP redirect back to the designated Index Page.
920 */
921 void fossil_redirect_home(void){
922 cgi_redirectf("%s%s", g.zTop, db_get("index-page", "/index"));
923 }
924
925 /*
926 ** If running as root, chroot to the directory containing the
927
--- src/main.c
+++ src/main.c
@@ -400,20 +400,20 @@
400 }
401
402 /*
403 ** Exit. Take care to close the database first.
404 */
405 NORETURN void fossil_exit(int rc){
406 db_close(1);
407 exit(rc);
408 }
409
410 /*
411 ** Print an error message, rollback all databases, and quit. These
412 ** routines never return.
413 */
414 NORETURN void fossil_panic(const char *zFormat, ...){
415 char *z;
416 va_list ap;
417 static int once = 1;
418 mainInFatalError = 1;
419 va_start(ap, zFormat);
@@ -428,11 +428,11 @@
428 fossil_puts(zOut, 1);
429 }
430 db_force_rollback();
431 fossil_exit(1);
432 }
433 NORETURN void fossil_fatal(const char *zFormat, ...){
434 char *z;
435 va_list ap;
436 mainInFatalError = 1;
437 va_start(ap, zFormat);
438 z = vmprintf(zFormat, ap);
@@ -916,11 +916,11 @@
916 }
917
918 /*
919 ** Send an HTTP redirect back to the designated Index Page.
920 */
921 NORETURN void fossil_redirect_home(void){
922 cgi_redirectf("%s%s", g.zTop, db_get("index-page", "/index"));
923 }
924
925 /*
926 ** If running as root, chroot to the directory containing the
927

Keyboard Shortcuts

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