In November 2020, github user Buggynours introduced an if statement that did not previously exist, and branches on field_length >= 0.
https://github.com/MariaDB/server/commit/28af4212b6e2afe1d42729c9c36215ed8a8d38cb#diff-df4382972e2df64f7429b4c4b2037ddeff0c1d6970a5e13b4f98f7995c928cf0
if (fp->field_length >= 0) {
|
pcf->Length = fp->field_length;
|
|
// length is bytes for Connect, not characters
|
if (!strnicmp(chset, "utf8", 4))
|
pcf->Length /= 3;
|
|
} else {
|
pcf->Length= 256; // BLOB?
|
However, field_length is defined as uint32_t, and has been for at least 21 years.
Since this variable is unsigned, the if statement will always take the true branch. It will never take the false branch.
- What is the right behaviour here?
- Is the current version correct? ("Always take the true branch" → we should delete the nonsense false branch)
- Or is there some real case where the false branch should be taken but which is currently being ignored? (The false branch comment "BLOB?" strongly suggests yes)
- If so, this is a bug, and it has been merged into 10.2.37+, 10.3.28+, 10.4.18+, 10.5.9+, 10.6., 10.7., etc.
- Or something else?
This was caught by building with -Wtype-limits.
{"report":{"fcp":3215.8999996185303,"ttfb":273,"pageVisibility":"visible","entityId":119643,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"6fb94ad6-52b2-49ec-bcde-48a0f4ea045c","navigationType":0,"readyForUser":3329.5999999046326,"redirectCount":0,"resourceLoadedEnd":3255.3999996185303,"resourceLoadedStart":393.7999997138977,"resourceTiming":[{"duration":341.2000002861023,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":393.7999997138977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":393.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":735,"responseStart":0,"secureConnectionStart":0},{"duration":344.40000009536743,"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":394.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":394.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":738.5999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":1870.9000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":394.2999997138977,"connectEnd":394.2999997138977,"connectStart":394.2999997138977,"domainLookupEnd":394.2999997138977,"domainLookupStart":394.2999997138977,"fetchStart":394.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":826.3999996185303,"responseEnd":2265.199999809265,"responseStart":1057.5,"secureConnectionStart":394.2999997138977},{"duration":2319.8999996185303,"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":394.5,"connectEnd":394.5,"connectStart":394.5,"domainLookupEnd":394.5,"domainLookupStart":394.5,"fetchStart":394.5,"redirectEnd":0,"redirectStart":0,"requestStart":826,"responseEnd":2714.3999996185303,"responseStart":1054.3999996185303,"secureConnectionStart":394.5},{"duration":665.9000000953674,"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":394.69999980926514,"connectEnd":394.69999980926514,"connectStart":394.69999980926514,"domainLookupEnd":394.69999980926514,"domainLookupStart":394.69999980926514,"fetchStart":394.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":826.3999996185303,"responseEnd":1060.5999999046326,"responseStart":1057.8999996185303,"secureConnectionStart":394.69999980926514},{"duration":665.8000001907349,"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":394.8999996185303,"connectEnd":394.8999996185303,"connectStart":394.8999996185303,"domainLookupEnd":394.8999996185303,"domainLookupStart":394.8999996185303,"fetchStart":394.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":826.5999999046326,"responseEnd":1060.6999998092651,"responseStart":1058.5,"secureConnectionStart":394.8999996185303},{"duration":665.5999999046326,"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":395.19999980926514,"connectEnd":395.19999980926514,"connectStart":395.19999980926514,"domainLookupEnd":395.19999980926514,"domainLookupStart":395.19999980926514,"fetchStart":395.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":826.6999998092651,"responseEnd":1060.7999997138977,"responseStart":1058.7999997138977,"secureConnectionStart":395.19999980926514},{"duration":386.90000009536743,"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":395.3999996185303,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":395.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":782.2999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":665.3999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":395.5,"connectEnd":395.5,"connectStart":395.5,"domainLookupEnd":395.5,"domainLookupStart":395.5,"fetchStart":395.5,"redirectEnd":0,"redirectStart":0,"requestStart":826.7999997138977,"responseEnd":1060.8999996185303,"responseStart":1059.2999997138977,"secureConnectionStart":395.5},{"duration":424.09999990463257,"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":395.7999997138977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":395.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":819.8999996185303,"responseStart":0,"secureConnectionStart":0},{"duration":996.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":396,"connectEnd":396,"connectStart":396,"domainLookupEnd":396,"domainLookupStart":396,"fetchStart":396,"redirectEnd":0,"redirectStart":0,"requestStart":826.8999996185303,"responseEnd":1392.5,"responseStart":1059.6999998092651,"secureConnectionStart":396},{"duration":2296.300000190735,"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":396.7999997138977,"connectEnd":396.7999997138977,"connectStart":396.7999997138977,"domainLookupEnd":396.7999997138977,"domainLookupStart":396.7999997138977,"fetchStart":396.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":1378.1999998092651,"responseEnd":2693.0999999046326,"responseStart":2516.199999809265,"secureConnectionStart":396.7999997138977},{"duration":2296.5,"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":396.7999997138977,"connectEnd":396.7999997138977,"connectStart":396.7999997138977,"domainLookupEnd":396.7999997138977,"domainLookupStart":396.7999997138977,"fetchStart":396.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":1378.1999998092651,"responseEnd":2693.2999997138977,"responseStart":2552.5,"secureConnectionStart":396.7999997138977},{"duration":346.59999990463257,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":2421.699999809265,"connectEnd":2421.699999809265,"connectStart":2421.699999809265,"domainLookupEnd":2421.699999809265,"domainLookupStart":2421.699999809265,"fetchStart":2421.699999809265,"redirectEnd":0,"redirectStart":0,"requestStart":2421.699999809265,"responseEnd":2768.2999997138977,"responseStart":2768.199999809265,"secureConnectionStart":2421.699999809265},{"duration":246.59999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":3008.7999997138977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":3008.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":3255.3999996185303,"responseStart":0,"secureConnectionStart":0},{"duration":131.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":3010,"connectEnd":3010,"connectStart":3010,"domainLookupEnd":3010,"domainLookupStart":3010,"fetchStart":3010,"redirectEnd":0,"redirectStart":0,"requestStart":3010,"responseEnd":3141.699999809265,"responseStart":3141.699999809265,"secureConnectionStart":3010}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":52,"responseStart":273,"responseEnd":380,"domLoading":364,"domInteractive":3400,"domContentLoadedEventStart":3400,"domContentLoadedEventEnd":3444,"domComplete":3961,"loadEventStart":3961,"loadEventEnd":3961,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":3376.8999996185303},{"name":"bigPipe.sidebar-id.end","time":3377.5999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":3377.7999997138977},{"name":"bigPipe.activity-panel-pipe-id.end","time":3379.3999996185303},{"name":"activityTabFullyLoaded","time":3461.8999996185303}],"measures":[],"correlationId":"2459656aa975d0","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":105,"dbReadsTimeInMs":19,"dbConnsTimeInMs":30,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
danblack wrote:
This does not address the ambiguity or bug reported here. Following that change we have an {{if (unsigned_integer_field_length >= 0) }}, so we still have an impossible "false" branch.
If field lengths are supposed to be unsigned, and therefore cannot have negative values, then why is code that sets it to negative values getting written/approved/merged? What was the actual intent of the field_length < 0 case?
If developers don't have a consistent model of whether field lengths can have negative values or not, then suppressing the warning (by deleting the branch that assumes it can be negative) may be hiding a bug.