]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mkfs.cramfs: remove dead code [coverity scan]
authorKarel Zak <kzak@redhat.com>
Tue, 4 Aug 2015 09:26:45 +0000 (11:26 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 4 Aug 2015 09:33:57 +0000 (11:33 +0200)
There two possible ways, print error and exit on too long names or
truncate the filename -- but it's impossible to do both in the same
code :-) It seems that code already assumes warning on long names, so
let's remove errx() and keep the behavior in dependence on -E.

Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/mkfs.cramfs.c

index 5b64ad80a24544dffcf95ffde55c8056904729a2..0096cd444c1c0d937d0095ea06d46316b3dcc315 100644 (file)
@@ -319,12 +319,11 @@ static unsigned int parse_directory(struct entry *root_entry, const char *name,
                        }
                }
                namelen = strlen(dirent->d_name);
-               if (namelen > MAX_INPUT_NAMELEN)
-                       errx(MKFS_EX_ERROR,
-                               _("Very long (%zu bytes) filename `%s' found.\n"
-                                 " Please increase MAX_INPUT_NAMELEN in "
-                                 "mkcramfs.c and recompile.  Exiting."),
-                               namelen, dirent->d_name);
+               if (namelen > MAX_INPUT_NAMELEN) {
+                       namelen = MAX_INPUT_NAMELEN;
+                       warn_namelen = 1;
+               }
+
                memcpy(endpath, dirent->d_name, namelen + 1);
 
                if (lstat(path, &st) < 0) {
@@ -333,15 +332,7 @@ static unsigned int parse_directory(struct entry *root_entry, const char *name,
                        continue;
                }
                entry = xcalloc(1, sizeof(struct entry));
-               entry->name = (unsigned char *)xstrdup(dirent->d_name);
-               if (namelen > 255) {
-                       /* Can't happen when reading from ext2fs. */
-
-                       /* TODO: we ought to avoid chopping in half
-                          multi-byte UTF8 characters. */
-                       entry->name[namelen = 255] = '\0';
-                       warn_namelen = 1;
-               }
+               entry->name = (unsigned char *)xstrndup(dirent->d_name, namelen);
                entry->mode = st.st_mode;
                entry->size = st.st_size;
                entry->uid = st.st_uid;
@@ -891,7 +882,7 @@ int main(int argc, char **argv)
        if (warn_namelen)
                /* Can't happen when reading from ext2fs. */
                /* Bytes, not chars: think UTF8. */
-               warnx(_("warning: filenames truncated to 255 bytes."));
+               warnx(_("warning: filenames truncated to %u bytes."), MAX_INPUT_NAMELEN);
        if (warn_skip)
                warnx(_("warning: files were skipped due to errors."));
        if (warn_size)