parser/expat/lib/xmlparse.c(2604): warning C4311: 'type cast': pointer truncation from 'const char *' to 'unsigned long'

RESOLVED FIXED in Firefox 48

Status

()

defect
RESOLVED FIXED
4 years ago
4 years ago

People

(Reporter: gps, Assigned: gps)

Tracking

unspecified
mozilla48
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(firefox48 fixed)

Details

Attachments

(1 attachment, 1 obsolete attachment)

Seeing multiple compilation warnings converted to errors when building on Visual Studio 2015 Update 1 in automation.

 22:46:35     INFO -  xmlparse.c
 22:46:35     INFO -  c:/builds/moz2_slave/try-w64-0000000000000000000000/build/src/parser/expat/lib/xmlparse.c(2604): error C2220: warning treated as error - no 'object' file generated
 22:46:35     INFO -  Warning: C4311 in c:\builds\moz2_slave\try-w64-0000000000000000000000\build\src\parser\expat\lib\xmlparse.c: 'type cast': pointer truncation from 'const char *' to 'unsigned long'
 22:46:35     INFO -  c:/builds/moz2_slave/try-w64-0000000000000000000000/build/src/parser/expat/lib/xmlparse.c(2604): warning C4311: 'type cast': pointer truncation from 'const char *' to 'unsigned long'
 22:46:35     INFO -  Warning: C4311 in c:\builds\moz2_slave\try-w64-0000000000000000000000\build\src\parser\expat\lib\xmlparse.c: 'type cast': pointer truncation from 'const char *' to 'unsigned long'
 22:46:35     INFO -  c:/builds/moz2_slave/try-w64-0000000000000000000000/build/src/parser/expat/lib/xmlparse.c(2632): warning C4311: 'type cast': pointer truncation from 'const char *' to 'unsigned long'
 22:46:35     INFO -  Warning: C4311 in c:\builds\moz2_slave\try-w64-0000000000000000000000\build\src\parser\expat\lib\xmlparse.c: 'type cast': pointer truncation from 'const char *' to 'unsigned long'
 22:46:35     INFO -  c:/builds/moz2_slave/try-w64-0000000000000000000000/build/src/parser/expat/lib/xmlparse.c(3294): warning C4311: 'type cast': pointer truncation from 'const char *' to 'unsigned long'
 22:46:35     INFO -  Warning: C4311 in c:\builds\moz2_slave\try-w64-0000000000000000000000\build\src\parser\expat\lib\xmlparse.c: 'type cast': pointer truncation from 'const char *' to 'unsigned long'
 22:46:35     INFO -  c:/builds/moz2_slave/try-w64-0000000000000000000000/build/src/parser/expat/lib/xmlparse.c(5376): warning C4311: 'type cast': pointer truncation from 'const char *' to 'unsigned long'
22:46:35 INFO - c:/builds/moz2_slave/try-w64-0000000000000000000000/build/src/config/rules.mk:891: recipe for target 'xmlparse.obj' failed
As part of unblocking building with VS2015u1 in automation, I'm mass
disabling compiler warnings that are turned into errors. This is not
the preferred mechanism to fix compilation warnings. So hopefully
this patch never lands because someone insists on fixing the underlying
problem instead. But if it does land, hopefully the workaround is
only temporary.

Review commit: https://reviewboard.mozilla.org/r/39995/diff/#index_header
See other reviews: https://reviewboard.mozilla.org/r/39995/
Attachment #8730558 - Flags: review?(peterv)
This is presumably coming from [1]:

> #define MUST_CONVERT(enc, s) (!(enc)->isUtf16 || (((unsigned long)s) & 1))

My understanding is we always convert to UTF-16 prior to handing off to libexpat, so the first part would be true, and we'll hit the second. I have no idea what the goal of the second part is...I guess it's checking pointer alignment to determine if it needs to skip a byte? If that's the case, again it's probably harmless as it's testing the lowest bit, so truncation shouldn't be an issue.

[1] https://dxr.mozilla.org/mozilla-central/rev/d6ee82b9a74155b6bfd544166f036fc572ae8c56/parser/expat/lib/xmlparse.c#29
Comment on attachment 8730558 [details]
MozReview Request: Bug 1256558 - Disable C4311 to unblock compilation on VS2015; r?peterv

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/39995/diff/1-2/
Trunk expat has

/* Using pointer subtraction to convert to integer type. */
#define MUST_CONVERT(enc, s) (!(enc)->isUtf16 || (((char *)(s) - (char *)NULL) & 1))

Does that solve the warning? We could just cherrypick that.
Flags: needinfo?(gps)
https://treeherder.mozilla.org/#/jobs?repo=try&revision=446b041868bd should have results in <1 hr.
Flags: needinfo?(gps)
The Try push looks happy.
This code is cherry picked from the trunk version of expat.

Review commit: https://reviewboard.mozilla.org/r/41487/diff/#index_header
See other reviews: https://reviewboard.mozilla.org/r/41487/
Attachment #8732979 - Flags: review?(peterv)
Attachment #8730558 - Attachment is obsolete: true
Attachment #8730558 - Flags: review?(peterv)
Comment on attachment 8732979 [details]
MozReview Request: Bug 1256558 - Change MUST_CONVERT to avoid C4311 in VS2015; r?peterv

https://reviewboard.mozilla.org/r/41487/#review37989
Attachment #8732979 - Flags: review+
Attachment #8732979 - Flags: review?(peterv)
Assignee: nobody → gps
Status: NEW → ASSIGNED
https://hg.mozilla.org/mozilla-central/rev/4c575b4f5492
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla48
You need to log in before you can comment on or make changes to this bug.