- snprintf(invname, sizeof(invname), "%s" SLASH "%s", filename, ent->d_name);
+
+ if((size_t)snprintf(invname, sizeof(invname), "%s" SLASH "%s", filename, ent->d_name) >= sizeof(invname)) {
+ fprintf(stderr, "Filename too long: %s" SLASH "%s\n", filename, ent->d_name);
+ continue;
+ }