Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-21978

make my_vsnprintf to use gcc-compatible format extensions

Details

    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
      • %T takes string and print it like %s but if the string should be truncated puts "..." at the end

      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

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

      It'll also need %sS as a synonym for %s as a form of escaping. In case someone needs to print a string, followed by T — using %sT will not do it anymore, so %sST can be used instead.

      Old formats can still be supported or they can be removed. The major version of the service should be increased either way to signal an incompatible change (different semantics for, e.g., %sT).

      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.

      Attachments

        Issue Links

          There are no Sub-Tasks for this issue.

          Activity

            Transition Time In Source Status Execution Times
            Sergei Golubchik made transition -
            Open In Progress
            1623d 14h 8m 1
            Sergei Golubchik made transition -
            In Progress In Review
            7s 1
            Brandon Nesterenko made transition -
            Stalled In Testing
            6s 1
            Brandon Nesterenko made transition -
            In Testing Stalled
            33d 23h 26m 1
            Jimmy Hú made transition -
            Stalled In Review
            1d 9h 42m 1
            Brandon Nesterenko made transition -
            In Review Stalled
            108d 17h 56m 2
            Jimmy Hú made transition -
            Stalled Closed
            23d 6h 23m 1

            People

              ParadoxV5 Jimmy Hú
              serg Sergei Golubchik
              Votes:
              1 Vote for this issue
              Watchers:
              10 Start 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.