[Pkg-shadow-commits] r2006 - in upstream/trunk: . libmisc
nekral-guest at alioth.debian.org
nekral-guest at alioth.debian.org
Sat May 24 15:19:03 UTC 2008
Author: nekral-guest
Date: 2008-05-24 15:19:02 +0000 (Sat, 24 May 2008)
New Revision: 2006
Modified:
upstream/trunk/ChangeLog
upstream/trunk/libmisc/copydir.c
upstream/trunk/libmisc/fields.c
Log:
* libmisc/fields.c: Avoid assignments in comparisons, assignments
with post increments (x++), use of integers as booleans, and
explicitly mark blocks with brackets.
* libmisc/copydir.c: Likewise.
* libmisc/fields.c: Add comments.
* libmisc/copydir.c: Mark function whose return value is not
checked as such.
* libmisc/copydir.c (remove_tree): Make sure unlink is successful
when removing files.
Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog 2008-05-24 14:11:31 UTC (rev 2005)
+++ upstream/trunk/ChangeLog 2008-05-24 15:19:02 UTC (rev 2006)
@@ -1,5 +1,10 @@
2008-05-24 Nicolas François <nicolas.francois at centraliens.net>
+ * libmisc/copydir.c (remove_tree): Make sure unlink is successful
+ when removing files.
+
+2008-05-24 Nicolas François <nicolas.francois at centraliens.net>
+
* libmisc/pwdcheck.c: Simply passwd_check since it's never used
when configured with PAM support.
@@ -15,6 +20,11 @@
* libmisc/list.c: Avoid assignments in comparisons, assignments
with post increments (x++), use of integers as booleans, and
explicitly mark blocks with brackets.
+ * libmisc/fields.c: Likewise.
+ * libmisc/copydir.c: Likewise.
+ * libmisc/fields.c: Add comments.
+ * libmisc/copydir.c: Mark function whose return value is not
+ checked as such.
2008-05-23 Nicolas François <nicolas.francois at centraliens.net>
Modified: upstream/trunk/libmisc/copydir.c
===================================================================
--- upstream/trunk/libmisc/copydir.c 2008-05-24 14:11:31 UTC (rev 2005)
+++ upstream/trunk/libmisc/copydir.c 2008-05-24 15:19:02 UTC (rev 2006)
@@ -250,7 +250,7 @@
}
}
}
- closedir (dir);
+ (void) closedir (dir);
if (set_orig) {
src_orig = 0;
@@ -412,7 +412,7 @@
return -1;
}
oldlink[len] = '\0'; /* readlink() does not NUL-terminate */
- if (!strncmp (oldlink, src_orig, strlen (src_orig))) {
+ if (strncmp (oldlink, src_orig, strlen (src_orig)) == 0) {
snprintf (dummy, sizeof dummy, "%s%s",
dst_orig,
oldlink + strlen (src_orig));
@@ -533,7 +533,7 @@
(uid == -1) ? statp->st_uid : (uid_t) uid,
(gid == -1) ? statp->st_gid : (gid_t) gid) != 0)
|| (chmod (dst, statp->st_mode & 07777) != 0)) {
- close (ifd);
+ (void) close (ifd);
return -1;
}
@@ -543,7 +543,7 @@
}
}
- close (ifd);
+ (void) close (ifd);
if (futimes (ofd, mt) != 0) {
return -1;
@@ -622,19 +622,22 @@
* Recursively delete this directory.
*/
- if (remove_tree (new_name)) {
+ if (remove_tree (new_name) != 0) {
err = -1;
break;
}
- if (rmdir (new_name)) {
+ if (rmdir (new_name) != 0) {
err = -1;
break;
}
- continue;
+ } else {
+ if (unlink (new_name) != 0) {
+ err = -1;
+ break;
+ }
}
- unlink (new_name);
}
- closedir (dir);
+ (void) closedir (dir);
return err;
}
Modified: upstream/trunk/libmisc/fields.c
===================================================================
--- upstream/trunk/libmisc/fields.c 2008-05-24 14:11:31 UTC (rev 2005)
+++ upstream/trunk/libmisc/fields.c 2008-05-24 15:19:02 UTC (rev 2006)
@@ -38,6 +38,7 @@
#include <string.h>
#include <stdio.h>
#include "prototypes.h"
+
/*
* valid_field - insure that a field contains all legal characters
*
@@ -53,15 +54,22 @@
const char *cp;
int err = 0;
- for (cp = field; *cp && !strchr (illegal, *cp); cp++);
+ /* For each character of field, search if it appears in the list
+ * of illegal characters. */
+ for (cp = field; '\0' != *cp; cp++) {
+ if (strchr (illegal, *cp) != NULL) {
+ err = -1;
+ break;
+ }
+ }
- if (*cp) {
- err = -1;
- } else {
- for (cp = field; *cp && isprint (*cp); cp++);
-
- if (*cp) {
- err = 1;
+ if (0 == err) {
+ /* Search if there are some non-printable characters */
+ for (cp = field; '\0' != *cp; cp++) {
+ if (!isprint (*cp)) {
+ err = 1;
+ break;
+ }
}
}
@@ -74,25 +82,28 @@
* prompt the user with the name of the field being changed and the
* current value.
*/
-
void change_field (char *buf, size_t maxsize, const char *prompt)
{
char newf[200];
char *cp;
- if (maxsize > sizeof (newf))
+ if (maxsize > sizeof (newf)) {
maxsize = sizeof (newf);
+ }
printf ("\t%s [%s]: ", prompt, buf);
- fflush (stdout);
- if (fgets (newf, maxsize, stdin) != newf)
+ (void) fflush (stdout);
+ if (fgets (newf, (int) maxsize, stdin) != newf) {
return;
+ }
- if (!(cp = strchr (newf, '\n')))
+ cp = strchr (newf, '\n');
+ if (NULL == cp) {
return;
+ }
*cp = '\0';
- if (newf[0]) {
+ if ('\0' != newf[0]) {
/*
* Remove leading and trailing whitespace. This also
* makes it possible to change the field to empty, by
@@ -100,11 +111,13 @@
*/
while (--cp >= newf && isspace (*cp));
- *++cp = '\0';
+ cp++;
+ *cp = '\0';
cp = newf;
- while (*cp && isspace (*cp))
+ while (('\0' != *cp) && isspace (*cp)) {
cp++;
+ }
strncpy (buf, cp, maxsize - 1);
buf[maxsize - 1] = '\0';
More information about the Pkg-shadow-commits
mailing list