Skip to content

Commit 9d7b35d

Browse files
authored
[NFC][GOFF] Fix char overflow (#112826)
This is one of the many PRs to fix errors with LLVM_ENABLE_WERROR=on. Built by GCC 11. Fix warnining: llvm/unittests/Object/GOFFObjectFileTest.cpp:511:17: error: overflow in conversion from ‘int’ to ‘char’ changes value from ‘240’ to ‘'\37777777760'’ [-Werror=overflow] 511 | GOFFData[1] = 0xF0;
1 parent e13f1d1 commit 9d7b35d

File tree

1 file changed

+56
-56
lines changed

1 file changed

+56
-56
lines changed

llvm/unittests/Object/GOFFObjectFileTest.cpp

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -507,72 +507,72 @@ TEST(GOFFObjectFileTest, TXTConstruct) {
507507
char GOFFData[GOFF::RecordLength * 6] = {};
508508

509509
// HDR record.
510-
GOFFData[0] = 0x03;
511-
GOFFData[1] = 0xF0;
512-
GOFFData[50] = 0x01;
510+
GOFFData[0] = (char)0x03;
511+
GOFFData[1] = (char)0xF0;
512+
GOFFData[50] = (char)0x01;
513513

514514
// ESD record.
515-
GOFFData[GOFF::RecordLength] = 0x03;
516-
GOFFData[GOFF::RecordLength + 7] = 0x01; // ESDID.
517-
GOFFData[GOFF::RecordLength + 71] = 0x05; // Size of symbol name.
518-
GOFFData[GOFF::RecordLength + 72] = 0xa5; // Symbol name is v.
519-
GOFFData[GOFF::RecordLength + 73] = 0x81; // Symbol name is a.
520-
GOFFData[GOFF::RecordLength + 74] = 0x99; // Symbol name is r.
521-
GOFFData[GOFF::RecordLength + 75] = 0x7b; // Symbol name is #.
522-
GOFFData[GOFF::RecordLength + 76] = 0x83; // Symbol name is c.
515+
GOFFData[GOFF::RecordLength] = (char)0x03;
516+
GOFFData[GOFF::RecordLength + 7] = (char)0x01; // ESDID.
517+
GOFFData[GOFF::RecordLength + 71] = (char)0x05; // Size of symbol name.
518+
GOFFData[GOFF::RecordLength + 72] = (char)0xa5; // Symbol name is v.
519+
GOFFData[GOFF::RecordLength + 73] = (char)0x81; // Symbol name is a.
520+
GOFFData[GOFF::RecordLength + 74] = (char)0x99; // Symbol name is r.
521+
GOFFData[GOFF::RecordLength + 75] = (char)0x7b; // Symbol name is #.
522+
GOFFData[GOFF::RecordLength + 76] = (char)0x83; // Symbol name is c.
523523

524524
// ESD record.
525-
GOFFData[GOFF::RecordLength * 2] = 0x03;
526-
GOFFData[GOFF::RecordLength * 2 + 3] = 0x01;
527-
GOFFData[GOFF::RecordLength * 2 + 7] = 0x02; // ESDID.
528-
GOFFData[GOFF::RecordLength * 2 + 11] = 0x01; // Parent ESDID.
529-
GOFFData[GOFF::RecordLength * 2 + 27] = 0x08; // Length.
530-
GOFFData[GOFF::RecordLength * 2 + 40] = 0x01; // Name Space ID.
531-
GOFFData[GOFF::RecordLength * 2 + 41] = 0x80;
532-
GOFFData[GOFF::RecordLength * 2 + 60] = 0x04; // Size of symbol name.
533-
GOFFData[GOFF::RecordLength * 2 + 61] = 0x04; // Size of symbol name.
534-
GOFFData[GOFF::RecordLength * 2 + 63] = 0x0a; // Size of symbol name.
535-
GOFFData[GOFF::RecordLength * 2 + 66] = 0x03; // Size of symbol name.
536-
GOFFData[GOFF::RecordLength * 2 + 71] = 0x08; // Size of symbol name.
537-
GOFFData[GOFF::RecordLength * 2 + 72] = 0xc3; // Symbol name is c.
538-
GOFFData[GOFF::RecordLength * 2 + 73] = 0x6d; // Symbol name is _.
539-
GOFFData[GOFF::RecordLength * 2 + 74] = 0xc3; // Symbol name is c.
540-
GOFFData[GOFF::RecordLength * 2 + 75] = 0xd6; // Symbol name is o.
541-
GOFFData[GOFF::RecordLength * 2 + 76] = 0xc4; // Symbol name is D.
542-
GOFFData[GOFF::RecordLength * 2 + 77] = 0xc5; // Symbol name is E.
543-
GOFFData[GOFF::RecordLength * 2 + 78] = 0xf6; // Symbol name is 6.
544-
GOFFData[GOFF::RecordLength * 2 + 79] = 0xf4; // Symbol name is 4.
525+
GOFFData[GOFF::RecordLength * 2] = (char)0x03;
526+
GOFFData[GOFF::RecordLength * 2 + 3] = (char)0x01;
527+
GOFFData[GOFF::RecordLength * 2 + 7] = (char)0x02; // ESDID.
528+
GOFFData[GOFF::RecordLength * 2 + 11] = (char)0x01; // Parent ESDID.
529+
GOFFData[GOFF::RecordLength * 2 + 27] = (char)0x08; // Length.
530+
GOFFData[GOFF::RecordLength * 2 + 40] = (char)0x01; // Name Space ID.
531+
GOFFData[GOFF::RecordLength * 2 + 41] = (char)0x80;
532+
GOFFData[GOFF::RecordLength * 2 + 60] = (char)0x04; // Size of symbol name.
533+
GOFFData[GOFF::RecordLength * 2 + 61] = (char)0x04; // Size of symbol name.
534+
GOFFData[GOFF::RecordLength * 2 + 63] = (char)0x0a; // Size of symbol name.
535+
GOFFData[GOFF::RecordLength * 2 + 66] = (char)0x03; // Size of symbol name.
536+
GOFFData[GOFF::RecordLength * 2 + 71] = (char)0x08; // Size of symbol name.
537+
GOFFData[GOFF::RecordLength * 2 + 72] = (char)0xc3; // Symbol name is c.
538+
GOFFData[GOFF::RecordLength * 2 + 73] = (char)0x6d; // Symbol name is _.
539+
GOFFData[GOFF::RecordLength * 2 + 74] = (char)0xc3; // Symbol name is c.
540+
GOFFData[GOFF::RecordLength * 2 + 75] = (char)0xd6; // Symbol name is o.
541+
GOFFData[GOFF::RecordLength * 2 + 76] = (char)0xc4; // Symbol name is D.
542+
GOFFData[GOFF::RecordLength * 2 + 77] = (char)0xc5; // Symbol name is E.
543+
GOFFData[GOFF::RecordLength * 2 + 78] = (char)0xf6; // Symbol name is 6.
544+
GOFFData[GOFF::RecordLength * 2 + 79] = (char)0xf4; // Symbol name is 4.
545545

546546
// ESD record.
547-
GOFFData[GOFF::RecordLength * 3] = 0x03;
548-
GOFFData[GOFF::RecordLength * 3 + 3] = 0x02;
549-
GOFFData[GOFF::RecordLength * 3 + 7] = 0x03; // ESDID.
550-
GOFFData[GOFF::RecordLength * 3 + 11] = 0x02; // Parent ESDID.
551-
GOFFData[GOFF::RecordLength * 3 + 71] = 0x05; // Size of symbol name.
552-
GOFFData[GOFF::RecordLength * 3 + 72] = 0xa5; // Symbol name is v.
553-
GOFFData[GOFF::RecordLength * 3 + 73] = 0x81; // Symbol name is a.
554-
GOFFData[GOFF::RecordLength * 3 + 74] = 0x99; // Symbol name is r.
555-
GOFFData[GOFF::RecordLength * 3 + 75] = 0x7b; // Symbol name is #.
556-
GOFFData[GOFF::RecordLength * 3 + 76] = 0x83; // Symbol name is c.
547+
GOFFData[GOFF::RecordLength * 3] = (char)0x03;
548+
GOFFData[GOFF::RecordLength * 3 + 3] = (char)0x02;
549+
GOFFData[GOFF::RecordLength * 3 + 7] = (char)0x03; // ESDID.
550+
GOFFData[GOFF::RecordLength * 3 + 11] = (char)0x02; // Parent ESDID.
551+
GOFFData[GOFF::RecordLength * 3 + 71] = (char)0x05; // Size of symbol name.
552+
GOFFData[GOFF::RecordLength * 3 + 72] = (char)0xa5; // Symbol name is v.
553+
GOFFData[GOFF::RecordLength * 3 + 73] = (char)0x81; // Symbol name is a.
554+
GOFFData[GOFF::RecordLength * 3 + 74] = (char)0x99; // Symbol name is r.
555+
GOFFData[GOFF::RecordLength * 3 + 75] = (char)0x7b; // Symbol name is #.
556+
GOFFData[GOFF::RecordLength * 3 + 76] = (char)0x83; // Symbol name is c.
557557

558558
// TXT record.
559-
GOFFData[GOFF::RecordLength * 4] = 0x03;
560-
GOFFData[GOFF::RecordLength * 4 + 1] = 0x10;
561-
GOFFData[GOFF::RecordLength * 4 + 7] = 0x02;
562-
GOFFData[GOFF::RecordLength * 4 + 23] = 0x08; // Data Length.
563-
GOFFData[GOFF::RecordLength * 4 + 24] = 0x12;
564-
GOFFData[GOFF::RecordLength * 4 + 25] = 0x34;
565-
GOFFData[GOFF::RecordLength * 4 + 26] = 0x56;
566-
GOFFData[GOFF::RecordLength * 4 + 27] = 0x78;
567-
GOFFData[GOFF::RecordLength * 4 + 28] = 0x9a;
568-
GOFFData[GOFF::RecordLength * 4 + 29] = 0xbc;
569-
GOFFData[GOFF::RecordLength * 4 + 30] = 0xde;
570-
GOFFData[GOFF::RecordLength * 4 + 31] = 0xf0;
559+
GOFFData[GOFF::RecordLength * 4] = (char)0x03;
560+
GOFFData[GOFF::RecordLength * 4 + 1] = (char)0x10;
561+
GOFFData[GOFF::RecordLength * 4 + 7] = (char)0x02;
562+
GOFFData[GOFF::RecordLength * 4 + 23] = (char)0x08; // Data Length.
563+
GOFFData[GOFF::RecordLength * 4 + 24] = (char)0x12;
564+
GOFFData[GOFF::RecordLength * 4 + 25] = (char)0x34;
565+
GOFFData[GOFF::RecordLength * 4 + 26] = (char)0x56;
566+
GOFFData[GOFF::RecordLength * 4 + 27] = (char)0x78;
567+
GOFFData[GOFF::RecordLength * 4 + 28] = (char)0x9a;
568+
GOFFData[GOFF::RecordLength * 4 + 29] = (char)0xbc;
569+
GOFFData[GOFF::RecordLength * 4 + 30] = (char)0xde;
570+
GOFFData[GOFF::RecordLength * 4 + 31] = (char)0xf0;
571571

572572
// END record.
573-
GOFFData[GOFF::RecordLength * 5] = 0x03;
574-
GOFFData[GOFF::RecordLength * 5 + 1] = 0x40;
575-
GOFFData[GOFF::RecordLength * 5 + 11] = 0x06;
573+
GOFFData[GOFF::RecordLength * 5] = (char)0x03;
574+
GOFFData[GOFF::RecordLength * 5 + 1] = (char)0x40;
575+
GOFFData[GOFF::RecordLength * 5 + 11] = (char)0x06;
576576

577577
StringRef Data(GOFFData, GOFF::RecordLength * 6);
578578

0 commit comments

Comments
 (0)