<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>11672</bug_id>
          
          <creation_ts>2017-06-15 18:41:11 +0000</creation_ts>
          <short_desc>gcc 7 format-truncation off by one with O2</short_desc>
          <delta_ts>2018-05-10 08:01:50 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>OE-Core</product>
          <component>devtools / tool chain</component>
          <version>unspecified</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>2.5 M4</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Mark">mark.asselstine</reporter>
          <assigned_to name="Khem Raj">raj.khem</assigned_to>
          <cc>mark.hatle</cc>
    
    <cc>meta.mr.watcher</cc>
    
    <cc>meta.watcher</cc>
    
    <cc>raj.khem</cc>
    
    <cc>richard.purdie</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>74246</commentid>
    <comment_count>0</comment_count>
      <attachid>3823</attachid>
    <who name="Mark">mark.asselstine</who>
    <bug_when>2017-06-15 18:41:11 +0000</bug_when>
    <thetext>Created attachment 3823
example C file

If you have a program such as
---
#include &lt;stdio.h&gt;

int main(int argc, char **argv)
{
  int i = 0;
  char buffer[100];

  for(i=0; i &lt;= 999; i++)
    snprintf(buffer, 5, &quot;-%d&quot;, i);

  return 0;
}
---

and build it with something like:
x86_64-overc-linux-gcc --sysroot=/home/mark/build/overc/tmp/work/core2-64-overc-linux/lxc/2.0.8-r0/recipe-sysroot -Wall -Werror -m64 -march=core2 -mtune=core2 -msse3 -mfpmath=sse -fPIC -DPIC -O2 -c range.c -o range

where x86_64-overc-linux-gcc --version
x86_64-overc-linux-gcc (GCC) 7.1.0

You will get
---
range.c: In function &apos;main&apos;:
range.c:10:25: error: &apos;snprintf&apos; output may be truncated before the last format character [-Werror=format-truncation=]
     snprintf(buffer, 5, &quot;-%d&quot;, i);
                         ^~~~~
range.c:10:5: note: &apos;snprintf&apos; output between 3 and 6 bytes into a destination of size 5
     snprintf(buffer, 5, &quot;-%d&quot;, i);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
---

NOTE that to my surprise the check is not using the type size (which would be 12 -- 10 chars in an int, plus sign, plus null). It is in fact using the loop logic to determine range but incorrectly using 1000 even though the loop stops at 999.

Attached is a more extensive example which can be played with.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74248</commentid>
    <comment_count>1</comment_count>
    <who name="Mark">mark.asselstine</who>
    <bug_when>2017-06-15 18:48:03 +0000</bug_when>
    <thetext>This seems to be reported to gcc already as

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78969

NOTE they even note the issue in LXC which is where I ran into this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>75907</commentid>
    <comment_count>2</comment_count>
    <who name="Khem Raj">raj.khem</who>
    <bug_when>2017-08-16 16:26:08 +0000</bug_when>
    <thetext>This missed the 7.2 gcc release. I dont see it getting fixed by 2.4 release. Therefore moving it to 2.5</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80545</commentid>
    <comment_count>3</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2018-05-10 08:01:50 +0000</bug_when>
    <thetext>We now have gcc 7.3 everywhere including the stable branches which resolves this.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>3823</attachid>
            <date>2017-06-15 18:41:11 +0000</date>
            <delta_ts>2017-06-15 18:41:11 +0000</delta_ts>
            <desc>example C file</desc>
            <filename>range.c</filename>
            <type>text/x-csrc</type>
            <size>1302</size>
            <attacher name="Mark">mark.asselstine</attacher>
            
              <data encoding="base64">LyoKeDg2XzY0LW92ZXJjLWxpbnV4LWdjYyAtLXN5c3Jvb3Q9L2hvbWUvbWFyay9idWlsZC9vdmVy
Yy90bXAvd29yay9jb3JlMi02NC1vdmVyYy1saW51eC9seGMvMi4wLjgtcjAvcmVjaXBlLXN5c3Jv
b3QgLVdhbGwgLVdlcnJvciAtbTY0IC1tYXJjaD1jb3JlMiAtbXR1bmU9Y29yZTIgLW1zc2UzIC1t
ZnBtYXRoPXNzZSAtZlBJQyAtRFBJQyAtTzIgLWMgcmFuZ2UuYyAtbyByYW5nZQoKSSBhbSBzZWVp
bmcgdGhlIGZvbGxvd2luZzoKLS0tCnJhbmdlLmM6IEluIGZ1bmN0aW9uICdtYWluJzoKcmFuZ2Uu
YzozNjoyNTogZXJyb3I6ICdzbnByaW50Zicgb3V0cHV0IG1heSBiZSB0cnVuY2F0ZWQgYmVmb3Jl
IHRoZSBsYXN0IGZvcm1hdCBjaGFyYWN0ZXIgWy1XZXJyb3I9Zm9ybWF0LXRydW5jYXRpb249XQog
ICAgIHNucHJpbnRmKGJ1ZmZlciwgNSwgIi0lZCIsIGkpOwogICAgICAgICAgICAgICAgICAgICAg
ICAgXn5+fn4KcmFuZ2UuYzozNjo1OiBub3RlOiAnc25wcmludGYnIG91dHB1dCBiZXR3ZWVuIDMg
YW5kIDYgYnl0ZXMgaW50byBhIGRlc3RpbmF0aW9uIG9mIHNpemUgNQogICAgIHNucHJpbnRmKGJ1
ZmZlciwgNSwgIi0lZCIsIGkpOwogICA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