Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8364103

Convert existing sprintf-chains to stringStream

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • None
    • hotspot

      The remaining code sections that still build up strings manually using a chain of snprintf-like calls and manually counting the character offsets should be transformed to use stringStream instead.

      For one, that code is difficult to read and maintain.
      It is also error-prone: a common error would be to keep calling snprintf with the updated offset but the initial buffer length, which renders the snprintf truncation test void and risks overwriters.

      Example (correct but cumbersome):

      https://github.com/openjdk/jdk/blob/52155dbbb0107c5077a6be7edfd91d4311411fc3/src/hotspot/share/classfile/javaClasses.cpp#L2607-L2642

      Note: in order to notice truncations with stringStream, we must also add a method to recognize truncation. As in `stringStream::did_truncate()`.

            Unassigned Unassigned
            stuefe Thomas Stuefe
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: