Skip to content
Snippets Groups Projects
  • Arseny Kapoulkine's avatar
    95f013ba
    Refactor snprintf support · 95f013ba
    Arseny Kapoulkine authored
    Instead of branching code at each invocation site, use variadic macros
    to create a wrapping macro that use snprintf for the buffer of a
    statically known size.
    
    Variadic macros are supported by all C++11 compilers, as is snprintf;
    on MSVC 2005+ we don't necessarily have snprintf, but we can use
    _snprintf_s with _TRUNCATE to get the same behavior. In all other cases
    we fall back to sprintf, that (theoretically) can lead to a stack buffer
    overflow.
    
    In practice all snprintfs used in pugixml use buffers that should be
    large enough to never be overflown but snprintf is safe even if this is
    not the case.
    95f013ba
    History
    Refactor snprintf support
    Arseny Kapoulkine authored
    Instead of branching code at each invocation site, use variadic macros
    to create a wrapping macro that use snprintf for the buffer of a
    statically known size.
    
    Variadic macros are supported by all C++11 compilers, as is snprintf;
    on MSVC 2005+ we don't necessarily have snprintf, but we can use
    _snprintf_s with _TRUNCATE to get the same behavior. In all other cases
    we fall back to sprintf, that (theoretically) can lead to a stack buffer
    overflow.
    
    In practice all snprintfs used in pugixml use buffers that should be
    large enough to never be overflown but snprintf is safe even if this is
    not the case.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.