diff --git a/ChangeLog b/ChangeLog index 2406f93f..c0c9fe05 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,8 @@ * src/newusers.c: Fix typo. * src/useradd.c: Likewise. * lib/nscd.c: Remove unused variable. + * lib/prototypes.h, libmisc/cleanup.c, lib/spawn.c, src/chage.c: + Add splint annotations. 2011-10-15 Nicolas François diff --git a/lib/prototypes.h b/lib/prototypes.h index 2332744a..7a0bb2f7 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -83,9 +83,9 @@ extern int chown_tree (const char *root, extern void chown_tty (const struct passwd *); /* cleanup.c */ -typedef void (*cleanup_function) (/*@null@*/void *arg); -void add_cleanup (cleanup_function pcf, /*@null@*/void *arg); -void del_cleanup (cleanup_function pcf); +typedef /*@null@*/void (*cleanup_function) (/*@null@*/void *arg); +void add_cleanup (/*@notnull@*/cleanup_function pcf, /*@null@*/void *arg); +void del_cleanup (/*@notnull@*/cleanup_function pcf); void do_cleanups (void); /* cleanup_group.c */ @@ -340,7 +340,7 @@ extern int shell (const char *file, /*@null@*/const char *arg, char *const envp[ /* spawn.c */ extern int run_command (const char *cmd, const char *argv[], - const char *envp[], int *status); + /*@null@*/const char *envp[], /*@out@*/int *status); /* system.c */ extern int safe_system (const char *command, diff --git a/lib/spawn.c b/lib/spawn.c index 472f64db..da984019 100644 --- a/lib/spawn.c +++ b/lib/spawn.c @@ -38,8 +38,8 @@ #include "exitcodes.h" #include "prototypes.h" -int run_command (const char *cmd, const char *argv[], const char *envp[], - int *status) +int run_command (const char *cmd, const char *argv[], + /*@null@*/const char *envp[], /*@out@*/int *status) { pid_t pid, wpid; diff --git a/libmisc/cleanup.c b/libmisc/cleanup.c index def7c475..bd83a230 100644 --- a/libmisc/cleanup.c +++ b/libmisc/cleanup.c @@ -38,8 +38,11 @@ * The cleanup_functions stack. */ #define CLEANUP_FUNCTIONS 10 + +typedef /*@null@*/void * parg_t; + static cleanup_function cleanup_functions[CLEANUP_FUNCTIONS]; -static void * cleanup_function_args[CLEANUP_FUNCTIONS]; +static parg_t cleanup_function_args[CLEANUP_FUNCTIONS]; static pid_t cleanup_pid = 0; /* @@ -83,7 +86,7 @@ void do_cleanups (void) /* * add_cleanup - Add a cleanup_function to the cleanup_functions stack. */ -void add_cleanup (cleanup_function pcf, /*@null@*/void *arg) +void add_cleanup (/*@notnull@*/cleanup_function pcf, /*@null@*/void *arg) { unsigned int i; assert (NULL != pcf); @@ -103,7 +106,7 @@ void add_cleanup (cleanup_function pcf, /*@null@*/void *arg) /* * del_cleanup - Remove a cleanup_function from the cleanup_functions stack. */ -void del_cleanup (cleanup_function pcf) +void del_cleanup (/*@notnull@*/cleanup_function pcf) { unsigned int i; assert (NULL != pcf); diff --git a/src/chage.c b/src/chage.c index c5e8b469..37a610d2 100644 --- a/src/chage.c +++ b/src/chage.c @@ -91,7 +91,7 @@ static long inactdays; static long expdate; /* local function prototypes */ -static void usage (int status); +static /*@noreturn@*/void usage (int status); static void date_to_str (char *buf, size_t maxsize, time_t date); static int new_fields (void); static void print_date (time_t date); @@ -101,12 +101,12 @@ static void check_flags (int argc, int opt_index); static void check_perms (void); static void open_files (bool readonly); static void close_files (void); -static void fail_exit (int code); +static /*@noreturn@*/void fail_exit (int code); /* * fail_exit - do some cleanup and exit with the given error code */ -static void fail_exit (int code) +static /*@noreturn@*/void fail_exit (int code) { if (spw_locked) { if (spw_unlock () == 0) { @@ -138,8 +138,9 @@ static void fail_exit (int code) /* * usage - print command line syntax and exit */ -static void usage (int status) +static /*@noreturn@*/void usage (int status) { + (void) fputs (_("Usage: chage [options] LOGIN\n" "\n" "Options:\n" @@ -187,14 +188,14 @@ static int new_fields (void) (void) puts (_("Enter the new value, or press ENTER for the default")); (void) puts (""); - snprintf (buf, sizeof buf, "%ld", mindays); + (void) snprintf (buf, sizeof buf, "%ld", mindays); change_field (buf, sizeof buf, _("Minimum Password Age")); if ( (getlong (buf, &mindays) == 0) || (mindays < -1)) { return 0; } - snprintf (buf, sizeof buf, "%ld", maxdays); + (void) snprintf (buf, sizeof buf, "%ld", maxdays); change_field (buf, sizeof buf, _("Maximum Password Age")); if ( (getlong (buf, &maxdays) == 0) || (maxdays < -1)) { @@ -218,14 +219,14 @@ static int new_fields (void) } } - snprintf (buf, sizeof buf, "%ld", warndays); + (void) snprintf (buf, sizeof buf, "%ld", warndays); change_field (buf, sizeof buf, _("Password Expiration Warning")); if ( (getlong (buf, &warndays) == 0) || (warndays < -1)) { return 0; } - snprintf (buf, sizeof buf, "%ld", inactdays); + (void) snprintf (buf, sizeof buf, "%ld", inactdays); change_field (buf, sizeof buf, _("Password Inactive")); if ( (getlong (buf, &inactdays) == 0) || (inactdays < -1)) { @@ -261,7 +262,7 @@ static void print_date (time_t date) tp = gmtime (&date); if (NULL == tp) { - (void) printf ("time_t: %lu\n", date); + (void) printf ("time_t: %lu\n", (unsigned long)date); } else { (void) strftime (buf, sizeof buf, "%b %d, %Y", tp); (void) puts (buf); @@ -420,7 +421,7 @@ static void process_flags (int argc, char **argv) break; case 'h': usage (E_SUCCESS); - break; + /*@notreached@*/break; case 'I': Iflg = true; if ( (getlong (optarg, &inactdays) == 0) @@ -657,7 +658,8 @@ static void close_files (void) * * It will not return in case of error */ -static void update_age (const struct spwd *sp, const struct passwd *pw) +static void update_age (/*@null@*/const struct spwd *sp, + /*@notnull@*/const struct passwd *pw) { struct spwd spwent; @@ -709,7 +711,7 @@ static void update_age (const struct spwd *sp, const struct passwd *pw) /* * get_defaults - get the value of the fields not set from the command line */ -static void get_defaults (const struct spwd *sp) +static void get_defaults (/*@null@*/const struct spwd *sp) { /* * Set the fields that aren't being set from the command line from