File klibc-2.0.4-mv.patch of Package klibc

diff -Nurp klibc-2.0.4/usr/utils/mv.c klibc-2.0.4-mv/usr/utils/mv.c
--- klibc-2.0.4/usr/utils/mv.c	2014-07-26 03:15:07.000000000 +0300
+++ klibc-2.0.4-mv/usr/utils/mv.c	2014-09-22 05:48:56.943414843 +0300
@@ -9,54 +9,42 @@
 
 int main(int argc, char *argv[])
 {
-	int c, f;
-	char *p;
+	int c, f = 0;
 	struct stat sb;
 
-	f = 0;
 	do {
 		c = getopt(argc, argv, "f");
-		if (c == EOF)
-			break;
-
 		switch (c) {
-
 		case 'f':
 			f = 1;
-			break;
+			continue;
 		case '?':
-			fprintf(stderr, "%s: invalid option -%c\n",
-				argv[0], optopt);
+			fprintf(stderr, "%s: invalid option -%c\n", argv[0], optopt);
 			return 1;
 		}
-
-	} while (1);
+	} while (c != EOF);
 
 	if (optind == argc) {
 		fprintf(stderr, "Usage: %s [-f] source dest\n", argv[0]);
 		return 1;
 	}
 
-	memset(&sb, 0, sizeof(struct stat));
-	if (stat(argv[argc - 1], &sb) < 0 && argc - optind > 2) {
-		if (!(S_ISDIR(sb.st_mode))) {
-			fprintf(stderr,
-				"multiple targets and %s is not a directory\n",
-				argv[argc - 1]);
-			return 1;
-		}
+	if (stat(argv[argc - 1], &sb) < 0 && argc - optind > 2 &&
+	    !(S_ISDIR(sb.st_mode))) {
+		fprintf(stderr, "multiple targets and %s is not a directory\n", argv[argc - 1]);
+		return 1;
 	}
 
 	for (c = optind; c < argc - 1; c++) {
 		char target[PATH_MAX];
 
-		p = strrchr(argv[c], '/');
-		p++;
+		strncpy(target, argv[argc - 1], PATH_MAX);
+		if (S_ISDIR(sb.st_mode)) {
+			size_t l = strlen(target);
 
-		if (S_ISDIR(sb.st_mode))
-			snprintf(target, PATH_MAX, "%s/%s", argv[argc - 1], p);
-		else
-			snprintf(target, PATH_MAX, "%s", argv[argc - 1]);
+			target[l] = '/';
+			strncpy(target + l + 1, strrchr(argv[c], '/') + 1, PATH_MAX - l - 1);
+		}
 
 		if (f)
 			unlink(target);
openSUSE Build Service is sponsored by