@@ -698,10 +698,12 @@ static char const *mbcName(MbcType type) {
698
698
case MBC_WRONG_FEATURES:
699
699
case MBC_BAD_RANGE:
700
700
case MBC_BAD_TPP1:
701
+ // LCOV_EXCL_START
701
702
unreachable_ ();
702
703
}
703
704
704
705
unreachable_ ();
706
+ // LCOV_EXCL_STOP
705
707
}
706
708
707
709
static bool hasRAM (MbcType type) {
@@ -763,7 +765,7 @@ static bool hasRAM(MbcType type) {
763
765
break ;
764
766
}
765
767
766
- unreachable_ ();
768
+ unreachable_ (); // LCOV_EXCL_LINE
767
769
}
768
770
769
771
static uint8_t const nintendoLogo[] = {
@@ -814,7 +816,7 @@ static ssize_t readBytes(int fd, uint8_t *buf, size_t len) {
814
816
ssize_t ret = read (fd, buf, len);
815
817
816
818
if (ret == -1 && errno != EINTR) { // Return errors, unless we only were interrupted
817
- return -1 ;
819
+ return -1 ; // LCOV_EXCL_LINE
818
820
}
819
821
// EOF reached
820
822
if (ret == 0 ) {
@@ -841,7 +843,7 @@ static ssize_t writeBytes(int fd, uint8_t *buf, size_t len) {
841
843
ssize_t ret = write (fd, buf, len);
842
844
843
845
if (ret == -1 && errno != EINTR) { // Return errors, unless we only were interrupted
844
- return -1 ;
846
+ return -1 ; // LCOV_EXCL_LINE
845
847
}
846
848
// If anything was written, accumulate it, and continue
847
849
if (ret != -1 ) {
@@ -895,8 +897,10 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
895
897
ssize_t headerSize = (cartridgeType & 0xFF00 ) == TPP1 ? 0x154 : 0x150 ;
896
898
897
899
if (rom0Len == -1 ) {
900
+ // LCOV_EXCL_START
898
901
report (" FATAL: Failed to read \" %s\" 's header: %s\n " , name, strerror (errno));
899
902
return ;
903
+ // LCOV_EXCL_STOP
900
904
} else if (rom0Len < headerSize) {
901
905
report (
902
906
" FATAL: \" %s\" too short, expected at least %jd ($%jx) bytes, got only %jd\n " ,
@@ -1134,8 +1138,10 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
1134
1138
// write the header
1135
1139
if (input == output) {
1136
1140
if (lseek (output, 0 , SEEK_SET) == static_cast <off_t >(-1 )) {
1141
+ // LCOV_EXCL_START
1137
1142
report (" FATAL: Failed to rewind \" %s\" : %s\n " , name, strerror (errno));
1138
1143
return ;
1144
+ // LCOV_EXCL_STOP
1139
1145
}
1140
1146
// If modifying the file in-place, we only need to edit the header
1141
1147
// However, padding may have modified ROM0 (added padding), so don't in that case
@@ -1146,16 +1152,20 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
1146
1152
writeLen = writeBytes (output, rom0, rom0Len);
1147
1153
1148
1154
if (writeLen == -1 ) {
1155
+ // LCOV_EXCL_START
1149
1156
report (" FATAL: Failed to write \" %s\" 's ROM0: %s\n " , name, strerror (errno));
1150
1157
return ;
1158
+ // LCOV_EXCL_STOP
1151
1159
} else if (writeLen < rom0Len) {
1160
+ // LCOV_EXCL_START
1152
1161
report (
1153
1162
" FATAL: Could only write %jd of \" %s\" 's %jd ROM0 bytes\n " ,
1154
1163
static_cast <intmax_t >(writeLen),
1155
1164
name,
1156
1165
static_cast <intmax_t >(rom0Len)
1157
1166
);
1158
1167
return ;
1168
+ // LCOV_EXCL_STOP
1159
1169
}
1160
1170
1161
1171
// Output ROMX if it was buffered
@@ -1164,25 +1174,31 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
1164
1174
// so it's fine to cast to `size_t`
1165
1175
writeLen = writeBytes (output, romx.data (), totalRomxLen);
1166
1176
if (writeLen == -1 ) {
1177
+ // LCOV_EXCL_START
1167
1178
report (" FATAL: Failed to write \" %s\" 's ROMX: %s\n " , name, strerror (errno));
1168
1179
return ;
1180
+ // LCOV_EXCL_STOP
1169
1181
} else if (static_cast <size_t >(writeLen) < totalRomxLen) {
1182
+ // LCOV_EXCL_START
1170
1183
report (
1171
1184
" FATAL: Could only write %jd of \" %s\" 's %zu ROMX bytes\n " ,
1172
1185
static_cast <intmax_t >(writeLen),
1173
1186
name,
1174
1187
totalRomxLen
1175
1188
);
1176
1189
return ;
1190
+ // LCOV_EXCL_STOP
1177
1191
}
1178
1192
}
1179
1193
1180
1194
// Output padding
1181
1195
if (padValue != UNSPECIFIED) {
1182
1196
if (input == output) {
1183
1197
if (lseek (output, 0 , SEEK_END) == static_cast <off_t >(-1 )) {
1198
+ // LCOV_EXCL_START
1184
1199
report (" FATAL: Failed to seek to end of \" %s\" : %s\n " , name, strerror (errno));
1185
1200
return ;
1201
+ // LCOV_EXCL_STOP
1186
1202
}
1187
1203
}
1188
1204
memset (bank, padValue, sizeof (bank));
@@ -1196,8 +1212,10 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
1196
1212
// The return value is either -1, or at most `thisLen`,
1197
1213
// so it's fine to cast to `size_t`
1198
1214
if (static_cast <size_t >(ret) != thisLen) {
1215
+ // LCOV_EXCL_START
1199
1216
report (" FATAL: Failed to write \" %s\" 's padding: %s\n " , name, strerror (errno));
1200
1217
break ;
1218
+ // LCOV_EXCL_STOP
1201
1219
}
1202
1220
len -= thisLen;
1203
1221
}
@@ -1224,12 +1242,16 @@ static bool processFilename(char const *name) {
1224
1242
Defer closeInput{[&] { close (input); }};
1225
1243
struct stat stat;
1226
1244
if (fstat (input, &stat) == -1 ) {
1245
+ // LCOV_EXCL_START
1227
1246
report (" FATAL: Failed to stat \" %s\" : %s\n " , name, strerror (errno));
1228
- } else if (!S_ISREG (stat.st_mode )) { // TODO: Do we want to support other types?
1247
+ // LCOV_EXCL_STOP
1248
+ } else if (!S_ISREG (stat.st_mode )) { // TODO: Do we want to support FIFOs or symlinks?
1249
+ // LCOV_EXCL_START
1229
1250
report (
1230
1251
" FATAL: \" %s\" is not a regular file, and thus cannot be modified in-place\n " ,
1231
1252
name
1232
1253
);
1254
+ // LCOV_EXCL_STOP
1233
1255
} else if (stat.st_size < 0x150 ) {
1234
1256
// This check is in theory redundant with the one in `processFile`, but it
1235
1257
// prevents passing a file size of 0, which usually indicates pipes
@@ -1423,16 +1445,20 @@ int main(int argc, char *argv[]) {
1423
1445
}
1424
1446
1425
1447
case ' V' :
1448
+ // LCOV_EXCL_START
1426
1449
printf (" rgbfix %s\n " , get_package_version_string ());
1427
1450
exit (0 );
1451
+ // LCOV_EXCL_STOP
1428
1452
1429
1453
case ' v' :
1430
1454
fixSpec = FIX_LOGO | FIX_HEADER_SUM | FIX_GLOBAL_SUM;
1431
1455
break ;
1432
1456
1433
1457
default :
1458
+ // LCOV_EXCL_START
1434
1459
printUsage ();
1435
1460
exit (1 );
1461
+ // LCOV_EXCL_STOP
1436
1462
}
1437
1463
}
1438
1464
0 commit comments