Bug #102224 dtuple_get_nth_field is not const clean
Submitted: 11 Jan 23:14 Modified: 15 Jan 19:51
Reporter: david zhang Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[11 Jan 23:14] david zhang
Description:
dfield_t *dtuple_get_nth_field(const dtuple_t *tuple, ulint n) {
  ut_ad(tuple);
  ut_ad(n < tuple->n_fields);

  return ((dfield_t *)tuple->fields + n);
}

dtuple_get_nth_field() cast-away const-ness of dtuple, make it easy to modify member dfields, which would introduce bugs.

How to repeat:
read code 

https://github.com/mysql/mysql-server/blob/f8cdce86448a211511e8a039c62580ae16cb96f5/storag...

Suggested fix:
use overloading with const-correct functions

UNIV_INLINE
const dfield_t *dtuple_get_nth_field(const dtuple_t *tuple, ulint n);
UNIV_INLINE
dfield_t *dtuple_get_nth_field(dtuple_t *tuple, ulint n);
[12 Jan 13:07] MySQL Verification Team
HI Mr. zhang,

Thank you for your bug report.

We agree with your analysis, but have to note that this is a low priority bug.

Verified as reported.
[15 Jan 19:51] david zhang
thanks for verifying. i agree with your assessment.

fyi I attempted a fix for dtuple_get_nth_field(), appears easily fixable.  However, dtuple_get_nth_v_field() suffers from the issue and its fix is more involved.
[18 Jan 13:05] MySQL Verification Team
Thank you for the additional info.