OSDN Git Service

Fix operator precedence issue.
authorNicolas Capens <capn@google.com>
Mon, 25 Apr 2016 20:12:57 +0000 (16:12 -0400)
committerNicolas Capens <capn@google.com>
Tue, 26 Apr 2016 15:08:37 +0000 (15:08 +0000)
Addition evaluates before the ternary operator, which resulted in the wrong
sizes being computed.

Bug 28346104

Change-Id: Id28843132097a4fb1599eed19c05f479f16f1315
Reviewed-on: https://swiftshader-review.googlesource.com/5187
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
src/Reactor/DLL.cpp

index 729b640..8856d72 100644 (file)
 #define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE 0x0040\r
 #endif\r
 \r
-#ifndef IMAGE_DLLCHARACTERISTICS_NX_COMPAT \r
+#ifndef IMAGE_DLLCHARACTERISTICS_NX_COMPAT\r
 #define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100\r
 #endif\r
\r
+\r
 namespace sw\r
 {\r
        #ifdef _M_AMD64\r
@@ -72,7 +72,7 @@ namespace sw
                        const unsigned char *function = (const unsigned char*)i->first;\r
                        const std::vector<Relocation> &functionRelocations = i->second;\r
                        unsigned int location = functionList[function]->location;\r
-                       \r
+\r
                        for(unsigned int j = 0; j < functionRelocations.size(); j++)\r
                        {\r
                                unsigned int address = location + functionRelocations[j].offset;\r
@@ -108,7 +108,7 @@ namespace sw
                DOSheader.e_lfanew = sizeof(DOSheader);\r
 \r
                int base = 0x10000000;\r
-               int codePage = pageAlign(sizeof(DOSheader) + AMD64 ? sizeof(COFFheader64) : sizeof(COFFheader32));\r
+               int codePage = pageAlign(sizeof(DOSheader) + (AMD64 ? sizeof(COFFheader64) : sizeof(COFFheader32)));\r
                int exportsPage = codePage + pageAlign(codeSize);\r
                int exportsSize = (int)(sizeof(IMAGE_EXPORT_DIRECTORY) + functionList.size() * sizeof(void*) + (strlen(dllName) + 1));\r
                int relocPage = exportsPage + pageAlign(exportsSize);\r
@@ -227,7 +227,7 @@ namespace sw
                textSection.Misc.VirtualSize = pageAlign(codeSize);\r
                textSection.VirtualAddress = codePage;\r
                textSection.SizeOfRawData = fileAlign(codeSize);\r
-               textSection.PointerToRawData = fileAlign(sizeof(DOSheader) + AMD64 ? sizeof(COFFheader64) : sizeof(COFFheader32));\r
+               textSection.PointerToRawData = fileAlign(sizeof(DOSheader) + (AMD64 ? sizeof(COFFheader64) : sizeof(COFFheader32)));\r
                textSection.PointerToRelocations = 0;\r
                textSection.PointerToLinenumbers = 0;\r
                textSection.NumberOfRelocations = 0;\r
@@ -294,7 +294,7 @@ namespace sw
                if(file)\r
                {\r
                        fwrite(&DOSheader, 1, sizeof(DOSheader), file);\r
-                       \r
+\r
                        if(AMD64)\r
                        {\r
                                fwrite(&COFFheader64, 1, sizeof(COFFheader64), file);\r
@@ -308,7 +308,7 @@ namespace sw
                        fwrite(&exportsSection, 1, sizeof(textSection), file);\r
                        fwrite(&relocSection, 1, sizeof(relocSection), file);\r
                        fwrite(&constSection, 1, sizeof(constSection), file);\r
-                       \r
+\r
                        for(FunctionList::iterator i = functionList.begin(); i != functionList.end(); i++)\r
                        {\r
                                const void *function = i->first;\r
@@ -349,7 +349,7 @@ namespace sw
                        fwrite(dllName, 1, strlen(dllName) + 1, file);\r
 \r
                        fseek(file, relocSection.PointerToRawData, SEEK_SET);\r
-                       \r
+\r
                        for(PageRelocations::iterator i = pageRelocations.begin(); i != pageRelocations.end(); i++)\r
                        {\r
                                IMAGE_BASE_RELOCATION relocationBlock;\r