MDEV-34266 removed a #pragma that would silence a GCC warning about possible missing NUL terminator when invoking strncpy(). It looks like the warning depends on some optimization settings.
Initially I thought that the warning got smarter in GCC 14, which was recently made the default compiler in Debian Sid, but I found examples of the warnings in the build logs also with GCC 12.2.0.
Attachments
Issue Links
is caused by
MDEV-34266safe_strcpy() includes an unnecessary conditional branch
This would result in another type of warning elsewhere, which I guess would also be output by some older versions of GCC:
10.6 2e580dc2a8da4aaf3a7f1b3cfb4f897dbb5f7089 with patch
In file included from /mariadb/10.6/include/my_bitmap.h:22,
from /mariadb/10.6/sql/log_event.h:36,
from /mariadb/10.6/sql/rpl_parallel.h:4,
from /mariadb/10.6/sql/rpl_parallel.cc:2:
/mariadb/10.6/include/m_string.h: In function ‘int rpt_handle_event(rpl_parallel_thread::queued_event*, rpl_parallel_thread*)’:
/mariadb/10.6/include/m_string.h:261:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 511 bytes from a string of length 511 [-Wstringop-truncation]
261 | strncpy(dst, src, dst_size);
| ^
/mariadb/10.6/include/m_string.h:261:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 511 bytes from a string of length 511 [-Wstringop-truncation]
/mariadb/10.6/include/m_string.h: In member function ‘rpl_parallel_thread::queued_event* rpl_parallel_thread::get_qev(Log_event*, ulonglong, Relay_log_info*)’:
/mariadb/10.6/include/m_string.h:261:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 511 bytes from a string of length 511 [-Wstringop-truncation]
/mariadb/10.6/include/m_string.h:261:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 511 bytes from a string of length 511 [-Wstringop-truncation]
/mariadb/10.6/include/m_string.h: In member function ‘rpl_parallel_thread::queued_event* rpl_parallel_thread::retry_get_qev(Log_event*, queued_event*, const char*, ulonglong, ulonglong)’:
/mariadb/10.6/include/m_string.h:261:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 511 bytes from a string of length 511 [-Wstringop-truncation]
/mariadb/10.6/include/m_string.h: In function ‘void* handle_rpl_parallel_thread(void*)’:
/mariadb/10.6/include/m_string.h:261:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 511 bytes from a string of length 511 [-Wstringop-truncation]
The 511 would likely be FN_REFLEN-1.
It looks like the #pragma must be reinstated to keep GCC 14 happy.
Marko Mäkelä
added a comment - Here is an example of a warning from GCC 14.2.0:
10.6 2e580dc2a8da4aaf3a7f1b3cfb4f897dbb5f7089
In file included from /mariadb/10.6/sql/sql_plugin.h:33,
from /mariadb/10.6/sql/mysqld.h:22,
from /mariadb/10.6/sql/semisync.h:21,
from /mariadb/10.6/sql/semisync_master.h:22,
from /mariadb/10.6/sql/semisync_master.cc:20:
/mariadb/10.6/include/m_string.h: In member function ‘int Repl_semi_sync_master::report_binlog_update(THD*, THD*, const char*, my_off_t)’:
/mariadb/10.6/include/m_string.h:260:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ specified bound 512 equals destination size [-Wstringop-truncation]
260 | strncpy(dst, src, dst_size);
| ^
I tried to fix it with the following patch:
diff --git a/include/m_string.h b/include/m_string.h
index 0cd6ff4513e..f9b8656623d 100644
--- a/include/m_string.h
+++ b/include/m_string.h
@@ -249,6 +249,7 @@ static inline void lex_string_set3(LEX_CSTRING *lex_str, const char *c_str,
static inline void safe_strcpy(char *dst, size_t dst_size, const char *src)
{
DBUG_ASSERT(dst_size > 0);
+ dst_size--;
/* 1) IF there is a 0 byte in the first dst_size bytes of src, strncpy will
* 0-terminate dst, and pad dst with additional 0 bytes out to dst_size.
@@ -258,7 +259,7 @@ static inline void safe_strcpy(char *dst, size_t dst_size, const char *src)
*/
strncpy(dst, src, dst_size);
- dst[dst_size - 1]= 0;
+ dst[dst_size]= 0;
}
/**
This would result in another type of warning elsewhere, which I guess would also be output by some older versions of GCC:
10.6 2e580dc2a8da4aaf3a7f1b3cfb4f897dbb5f7089 with patch
In file included from /mariadb/10.6/include/my_bitmap.h:22,
from /mariadb/10.6/sql/log_event.h:36,
from /mariadb/10.6/sql/rpl_parallel.h:4,
from /mariadb/10.6/sql/rpl_parallel.cc:2:
/mariadb/10.6/include/m_string.h: In function ‘int rpt_handle_event(rpl_parallel_thread::queued_event*, rpl_parallel_thread*)’:
/mariadb/10.6/include/m_string.h:261:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 511 bytes from a string of length 511 [-Wstringop-truncation]
261 | strncpy(dst, src, dst_size);
| ^
/mariadb/10.6/include/m_string.h:261:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 511 bytes from a string of length 511 [-Wstringop-truncation]
/mariadb/10.6/include/m_string.h: In member function ‘rpl_parallel_thread::queued_event* rpl_parallel_thread::get_qev(Log_event*, ulonglong, Relay_log_info*)’:
/mariadb/10.6/include/m_string.h:261:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 511 bytes from a string of length 511 [-Wstringop-truncation]
/mariadb/10.6/include/m_string.h:261:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 511 bytes from a string of length 511 [-Wstringop-truncation]
/mariadb/10.6/include/m_string.h: In member function ‘rpl_parallel_thread::queued_event* rpl_parallel_thread::retry_get_qev(Log_event*, queued_event*, const char*, ulonglong, ulonglong)’:
/mariadb/10.6/include/m_string.h:261:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 511 bytes from a string of length 511 [-Wstringop-truncation]
/mariadb/10.6/include/m_string.h: In function ‘void* handle_rpl_parallel_thread(void*)’:
/mariadb/10.6/include/m_string.h:261:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 511 bytes from a string of length 511 [-Wstringop-truncation]
The 511 would likely be FN_REFLEN-1 .
It looks like the #pragma must be reinstated to keep GCC 14 happy.
People
Marko Mäkelä
Marko Mäkelä
Votes:
0Vote for this issue
Watchers:
1Start watching this issue
Dates
Created:
Updated:
Resolved:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":971.9000000953674,"ttfb":425.40000009536743,"pageVisibility":"visible","entityId":130339,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"720a1762-8a6f-4307-b20c-556eda85d74b","navigationType":0,"readyForUser":1034.3000001907349,"redirectCount":0,"resourceLoadedEnd":736.9000000953674,"resourceLoadedStart":432.59999990463257,"resourceTiming":[{"duration":40.60000038146973,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":432.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":432.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":473.2000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":40.80000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":433,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":433,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":473.80000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":92,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":433.09999990463257,"connectEnd":433.09999990463257,"connectStart":433.09999990463257,"domainLookupEnd":433.09999990463257,"domainLookupStart":433.09999990463257,"fetchStart":433.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":477,"responseEnd":525.0999999046326,"responseStart":490.80000019073486,"secureConnectionStart":433.09999990463257},{"duration":106.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":433.30000019073486,"connectEnd":433.30000019073486,"connectStart":433.30000019073486,"domainLookupEnd":433.30000019073486,"domainLookupStart":433.30000019073486,"fetchStart":433.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":478,"responseEnd":539.4000000953674,"responseStart":496.2000002861023,"secureConnectionStart":433.30000019073486},{"duration":81.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":433.40000009536743,"connectEnd":433.40000009536743,"connectStart":433.40000009536743,"domainLookupEnd":433.40000009536743,"domainLookupStart":433.40000009536743,"fetchStart":433.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":479.80000019073486,"responseEnd":514.5999999046326,"responseStart":514.0999999046326,"secureConnectionStart":433.40000009536743},{"duration":80.2999997138977,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":433.7000002861023,"connectEnd":433.7000002861023,"connectStart":433.7000002861023,"domainLookupEnd":433.7000002861023,"domainLookupStart":433.7000002861023,"fetchStart":433.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":481.2000002861023,"responseEnd":514,"responseStart":513.3000001907349,"secureConnectionStart":433.7000002861023},{"duration":83,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":433.80000019073486,"connectEnd":433.80000019073486,"connectStart":433.80000019073486,"domainLookupEnd":433.80000019073486,"domainLookupStart":433.80000019073486,"fetchStart":433.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":482.30000019073486,"responseEnd":516.8000001907349,"responseStart":516.2000002861023,"secureConnectionStart":433.80000019073486},{"duration":47.200000286102295,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":434,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":434,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":481.2000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":85.10000038146973,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":434.09999990463257,"connectEnd":434.09999990463257,"connectStart":434.09999990463257,"domainLookupEnd":434.09999990463257,"domainLookupStart":434.09999990463257,"fetchStart":434.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":484,"responseEnd":519.2000002861023,"responseStart":518.7000002861023,"secureConnectionStart":434.09999990463257},{"duration":48.40000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":434.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":434.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":482.7000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":85.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":434.40000009536743,"connectEnd":434.40000009536743,"connectStart":434.40000009536743,"domainLookupEnd":434.40000009536743,"domainLookupStart":434.40000009536743,"fetchStart":434.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":484.40000009536743,"responseEnd":519.9000000953674,"responseStart":519.3000001907349,"secureConnectionStart":434.40000009536743},{"duration":201.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":447.7000002861023,"connectEnd":447.7000002861023,"connectStart":447.7000002861023,"domainLookupEnd":447.7000002861023,"domainLookupStart":447.7000002861023,"fetchStart":447.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":575,"responseEnd":648.8000001907349,"responseStart":647.0999999046326,"secureConnectionStart":447.7000002861023},{"duration":283.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":453.09999990463257,"connectEnd":453.09999990463257,"connectStart":453.09999990463257,"domainLookupEnd":453.09999990463257,"domainLookupStart":453.09999990463257,"fetchStart":453.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":724,"responseEnd":736.9000000953674,"responseStart":736.3000001907349,"secureConnectionStart":453.09999990463257},{"duration":203.69999980926514,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":733.4000000953674,"connectEnd":733.4000000953674,"connectStart":733.4000000953674,"domainLookupEnd":733.4000000953674,"domainLookupStart":733.4000000953674,"fetchStart":733.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":900.9000000953674,"responseEnd":937.0999999046326,"responseStart":936.2000002861023,"secureConnectionStart":733.4000000953674}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":146,"responseStart":425,"responseEnd":453,"domLoading":429,"domInteractive":1104,"domContentLoadedEventStart":1104,"domContentLoadedEventEnd":1147,"domComplete":1662,"loadEventStart":1662,"loadEventEnd":1662,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1071.7000002861023},{"name":"bigPipe.sidebar-id.end","time":1072.5},{"name":"bigPipe.activity-panel-pipe-id.start","time":1072.5999999046326},{"name":"bigPipe.activity-panel-pipe-id.end","time":1075.0999999046326},{"name":"activityTabFullyLoaded","time":1164.3000001907349}],"measures":[],"correlationId":"9e5ffa66c8157d","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":108,"dbReadsTimeInMs":14,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Here is an example of a warning from GCC 14.2.0:
10.6 2e580dc2a8da4aaf3a7f1b3cfb4f897dbb5f7089
In file included from /mariadb/10.6/sql/sql_plugin.h:33,
from /mariadb/10.6/sql/mysqld.h:22,
from /mariadb/10.6/sql/semisync.h:21,
from /mariadb/10.6/sql/semisync_master.h:22,
from /mariadb/10.6/sql/semisync_master.cc:20:
/mariadb/10.6/include/m_string.h: In member function ‘int Repl_semi_sync_master::report_binlog_update(THD*, THD*, const char*, my_off_t)’:
/mariadb/10.6/include/m_string.h:260:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ specified bound 512 equals destination size [-Wstringop-truncation]
260 | strncpy(dst, src, dst_size);
| ^
I tried to fix it with the following patch:
diff --git a/include/m_string.h b/include/m_string.h
index 0cd6ff4513e..f9b8656623d 100644
--- a/include/m_string.h
+++ b/include/m_string.h
@@ -249,6 +249,7 @@ static inline void lex_string_set3(LEX_CSTRING *lex_str, const char *c_str,
static inline void safe_strcpy(char *dst, size_t dst_size, const char *src)
{
DBUG_ASSERT(dst_size > 0);
+ dst_size--;
/* 1) IF there is a 0 byte in the first dst_size bytes of src, strncpy will
* 0-terminate dst, and pad dst with additional 0 bytes out to dst_size.
@@ -258,7 +259,7 @@ static inline void safe_strcpy(char *dst, size_t dst_size, const char *src)
*/
strncpy(dst, src, dst_size);
- dst[dst_size - 1]= 0;
+ dst[dst_size]= 0;
}
This would result in another type of warning elsewhere, which I guess would also be output by some older versions of GCC:
10.6 2e580dc2a8da4aaf3a7f1b3cfb4f897dbb5f7089 with patch
In file included from /mariadb/10.6/include/my_bitmap.h:22,
from /mariadb/10.6/sql/log_event.h:36,
from /mariadb/10.6/sql/rpl_parallel.h:4,
from /mariadb/10.6/sql/rpl_parallel.cc:2:
/mariadb/10.6/include/m_string.h: In function ‘int rpt_handle_event(rpl_parallel_thread::queued_event*, rpl_parallel_thread*)’:
/mariadb/10.6/include/m_string.h:261:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 511 bytes from a string of length 511 [-Wstringop-truncation]
261 | strncpy(dst, src, dst_size);
| ^
/mariadb/10.6/include/m_string.h:261:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 511 bytes from a string of length 511 [-Wstringop-truncation]
/mariadb/10.6/include/m_string.h: In member function ‘rpl_parallel_thread::queued_event* rpl_parallel_thread::get_qev(Log_event*, ulonglong, Relay_log_info*)’:
/mariadb/10.6/include/m_string.h:261:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 511 bytes from a string of length 511 [-Wstringop-truncation]
/mariadb/10.6/include/m_string.h:261:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 511 bytes from a string of length 511 [-Wstringop-truncation]
/mariadb/10.6/include/m_string.h: In member function ‘rpl_parallel_thread::queued_event* rpl_parallel_thread::retry_get_qev(Log_event*, queued_event*, const char*, ulonglong, ulonglong)’:
/mariadb/10.6/include/m_string.h:261:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 511 bytes from a string of length 511 [-Wstringop-truncation]
/mariadb/10.6/include/m_string.h: In function ‘void* handle_rpl_parallel_thread(void*)’:
/mariadb/10.6/include/m_string.h:261:10: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 511 bytes from a string of length 511 [-Wstringop-truncation]
The 511 would likely be FN_REFLEN-1.
It looks like the #pragma must be reinstated to keep GCC 14 happy.