natalie-lang / natalie

a work-in-progress Ruby compiler, written in Ruby and C++

Home Page:https://natalie-lang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

memcmp bug

seven1m opened this issue · comments

I saw this warning scroll by when building Natalie in release mode using this Dockerfile. I'd never seen it before but figured I should document it before I forget:

remote: #12 75.89 In member function ‘bool TM::String::operator==(const char*) const’,                                                                                                                             
remote: #12 75.89     inlined from ‘Natalie::Value math_defn_frexp226(Natalie::Env*, Natalie::Value, Natalie::Args, Natalie::Block*)’ at build/generated/math.rb.cpp:763:34:                                       
remote: #12 75.89 /natalie/include/tm/string.hpp:863:22: warning: ‘int __builtin_memcmp_eq(const void*, const void*, long unsigned int)’ reading 13 bytes from a region of size 1 [-Wstringop-overflow=]           
remote: #12 75.89   863 |         return memcmp(c_str(), other, sizeof(char) * m_length) == 0;                                                                                                                     
remote: #12 75.89       |                ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   

...also, if we missed this before because of a warning we see in production mode but not in debug build mode, then we should fix that too.

This is a false alarm. It only warns on GCC 10; newer versions do not warn on this. We have an explicit length check on the line just above, so I'm confident this is not a real issue. I will use a newer Docker image version for natalie-lang.org.