[MDEV-21978] make my_vsnprintf to use gcc-compatible format extensions (Part-time project) Created: 2020-03-18  Updated: 2022-08-02

Status: Open
Project: MariaDB Server
Component/s: Plugins
Fix Version/s: 11.0

Type: Task Priority: Major
Reporter: Sergei Golubchik Assignee: Sergei Golubchik
Resolution: Unresolved Votes: 1
Labels: beginner-friendly, gsoc21, gsoc22

Issue Links:
Relates
relates to MDEV-19784 C++11 protectors for my_error In Review
relates to MDEV-22545 my_vsnprintf behaves not as in C stan... Closed

 Description   

my_vsnprintf() is used internally in the server as a portable printf replacement. And it's also exported to plugins as a service.

It supports a subset of printf formats and three extensions:

  • %`s means that a string should be quoted like an `identifier`
  • %b means that it's a binary string, not zero-terminated; printing won't stop at \0, so one should always specify the field width (like %.100b)
  • %M is used in error messages and prints the integer (errno) and the corresponding strerror() for it

gcc knows printf formats and check whether actual arguments match the format string and issue a warning if they don't. Unfortunately there seems to be no easy way to teach gcc our extensions, so for now we have to disable printf format checks.

An better approach would be to use gcc compatible format extensions, like Linux kernel does. We should migrate to a different syntax for our extensions

  • %sI to mean "print as an identifier"
  • %sB to mean "print a binary string"
  • %uE to mean "print an errno"
  • %sT to put a "..." as truncation indicator

old formats can still be supported or they can be removed and in the latter case the major version of the service should be increased to signal an incompatible change.

All error messages and all usages of my_vsnprintf should be changed to use the new syntax. One way to do it is to disable old syntax conditonally, only in debug builds. All gcc printf format checks should be enabled.



 Comments   
Comment by Daniel Black [ 2021-12-16 ]

wlad suggested %lluH , for Humanized formatting (MDEV-27158)

Comment by Lin, Cheng-Chieh [ 2022-04-12 ]

Hi, I'm a senior student of CSIE department of Cheng Kung University. I saw this task from Google Summer of Code 2022. I'm interested in this task but I haven't used or built MariaDB before. Can I assign this task?

Comment by Sergei Golubchik [ 2022-04-26 ]

blueskyson, the "Assignee" field in Jira can only be assigned to someone in a Developers group. But it doesn't matter much. If you'd like to do this task — please, by all means, do it, create a pull request, and pay no attention to the "Assignee" field.

Comment by Lin, Cheng-Chieh [ 2022-07-05 ]

Sorry I'm too busy on my work now. Maybe other people can do this task.

Generated at Thu Feb 08 09:11:16 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.