Closed Bug 1334979 Opened 8 years ago Closed 8 years ago

Fix a truncation leading to an error with gcc 7

Categories

(Toolkit :: General, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla54
Tracking Status
firefox54 --- fixed

People

(Reporter: Sylvestre, Assigned: Sylvestre)

References

Details

Attachments

(1 file)

0:35.60 /root/firefox-gcc-last/toolkit/components/ctypes/tests/jsctypes-test-finalizer.cpp: In function 'char* test_finalizer_acq_string_t(int)': 0:35.60 /root/firefox-gcc-last/toolkit/components/ctypes/tests/jsctypes-test-finalizer.cpp:231:1: error: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 10 [-Werror=format-truncation=] 0:35.60 test_finalizer_acq_string_t(int i) 0:35.60 ^~~~~~~~~~~~~~~~~~~~~~~~~~~ 0:35.60 /root/firefox-gcc-last/toolkit/components/ctypes/tests/jsctypes-test-finalizer.cpp:231:1: note: using the range [1, -2147483648] for directive argument 0:35.60 /root/firefox-gcc-last/toolkit/components/ctypes/tests/jsctypes-test-finalizer.cpp:236:13: note: format output between 2 and 12 bytes into a destination of size 10 0:35.60 snprintf(buf, 10, "%d", i); 0:35.60 ~~~~~~~~^~~~~~~~~~~~~~~~~~ Because: $ echo -n "-2147483648"|wc -c 11
Attachment #8831635 - Flags: review?(jorendorff) → review?(bbouvier)
Comment on attachment 8831635 [details] Bug 1334979 - Fix a truncation leading to an error with gcc 7 https://reviewboard.mozilla.org/r/108184/#review110856 ::: toolkit/components/ctypes/tests/jsctypes-test-finalizer.cpp:236 (Diff revision 1) > test_finalizer_acq_string_t(int i) > { > gFinalizerTestResources[i] = 1; > if (!gFinalizerTestNames[i]) { > char* buf = new char[10]; > - snprintf(buf, 10, "%d", i); > + snprintf(buf, 11, "%d", i); 1. http://en.cppreference.com/w/c/io/fprintf says that if bufsz is the second argument, at most bufsz-1 elements are written. So to write INT32_MIN, you need 11 chars, thus bufsz should be 12. 2. The line right above needs to be changed too, to allocate 12 chars (including the leading zero character), right?
Attachment #8831635 - Flags: review?(bbouvier)
Comment on attachment 8831635 [details] Bug 1334979 - Fix a truncation leading to an error with gcc 7 https://reviewboard.mozilla.org/r/108184/#review111024 Stealing review, assuming it should have been redirected to me. Please update the reviewer in the commit message. Thanks for the patch!
Attachment #8831635 - Flags: review+
Pushed by sledru@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/8be8dd1678a5 Fix a truncation leading to an error with gcc 7 r=bbouvier
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla54
Attachment #8831635 - Flags: review?(jorendorff)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: