This mapping has 3 multi-map groups: several pairings are equally correct there. The code view shows one arbitrary valid pairing, not the only one.

Before

1#include <qpdf/InputSource_private.hh>
2
3#include <qpdf/QIntC.hh>
4#include <qpdf/QTC.hh>
5#include <cstring>
6#include <stdexcept>
7
8using namespace std::literals;
9
10void
11InputSource::setLastOffset(qpdf_offset_t offset)
12{
13 this->last_offset = offset;
14}
15
…lines 16–69 unchanged (54 lines)
70 // specifically constructed to make sure we caught the edge cases in testing.
71
72 char buf[1025]; // size known to input_source.cc in libtests
73 // To enable us to guarantee null-termination, save an extra byte so that buf[size] is valid
74 // memory.
75 size_t size = sizeof(buf) - 1;
76 if ((strlen(start_chars) < 1) || (strlen(start_chars) > size)) {
77 throw std::logic_error(
78 "InputSource::findSource called with too small or too large of a character sequence");
79 }
80
81 char* p = nullptr;
82 qpdf_offset_t buf_offset = offset;
83 size_t bytes_read = 0;
84
85 // Guarantee that we return from this loop. Each time through, we either return, advance p, or
…lines 86–151 unchanged (66 lines)
152 ++p;
153 } else {
154 // Trigger reading the next block
155 p = buf + bytes_read;
156 }
157 }
158 throw std::logic_error("InputSource after while (true)");
159}
160
161bool
162InputSource::findLast(char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder)
163{
164 bool found = false;
…lines 165–183 unchanged (19 lines)

After

1#include <qpdf/InputSource_private.hh>
2
3#include <qpdf/QIntC.hh>
4#include <qpdf/QTC.hh>
5#include <qpdf/Util.hh>
6
7#include <cstring>
8#include <stdexcept>
9
10using namespace std::literals;
11using namespace qpdf;
12
13void
14InputSource::setLastOffset(qpdf_offset_t offset)
15{
16 this->last_offset = offset;
17}
…lines 18–72 unchanged (55 lines)
73 // specifically constructed to make sure we caught the edge cases in testing.
74
75 char buf[1025]; // size known to input_source.cc in libtests
76 // To enable us to guarantee null-termination, save an extra byte so that buf[size] is valid
77 // memory.
78 size_t size = sizeof(buf) - 1;
79 util::assertion(
80 !(strlen(start_chars) < 1 || strlen(start_chars) > size),
81 "InputSource::findSource called with too small or too large of a character sequence" //
82 );
83
84 char* p = nullptr;
85 qpdf_offset_t buf_offset = offset;
86 size_t bytes_read = 0;
87
88 // Guarantee that we return from this loop. Each time through, we either return, advance p, or
…lines 89–154 unchanged (66 lines)
155 ++p;
156 } else {
157 // Trigger reading the next block
158 p = buf + bytes_read;
159 }
160 }
161}
162
163bool
164InputSource::findLast(char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder)
165{
166 bool found = false;
167 qpdf_offset_t after_found_offset = 0;
…lines 168–185 unchanged (18 lines)

Before

translation_unit
preproc_include
#include "#include"
system_lib_string "<qpdf/InputSource_private.hh>"
preproc_include
#include "#include"
system_lib_string "<qpdf/QIntC.hh>"
preproc_include
#include "#include"
system_lib_string "<qpdf/QTC.hh>"
preproc_include
#include "#include"
system_lib_string "<cstring>"
preproc_include
#include "#include"
system_lib_string "<stdexcept>"
using_declaration
using "using"
namespace "namespace"
qualified_identifier
namespace_identifier "std"
:: "::"
identifier "literals"
; ";"
function_definition (+25 nodes collapsed)
function_definition (+22 nodes collapsed)
function_definition (+188 nodes collapsed)
function_definition (+28 nodes collapsed)
function_definition (+58 nodes collapsed)
function_definition
primitive_type "bool"
function_declarator (+29 nodes collapsed)
compound_statement
{ "{"
comment "// Basic approach: search for the first character of start_c"...
comment "// going past len (if len != 0). Once the first character is"...
comment "// of a sequence of characters matching start_chars. If so, "...
comment "// caller-specific additional checks. If not, keep searching"...
comment "// This code is tricky and highly subject to off-by-one or o"...
comment "// comments throughout that explain how we're not missing an"...
comment "// specifically constructed to make sure we caught the edge "...
declaration
primitive_type "char"
array_declarator
identifier "buf"
[ "["
number_literal "1025"
] "]"
; ";"
comment "// size known to input_source.cc in libtests"
comment "// To enable us to guarantee null-termination, save an extra"...
comment "// memory."
declaration
primitive_type "size_t"
init_declarator
identifier "size"
= "="
binary_expression
sizeof_expression
sizeof "sizeof"
parenthesized_expression
( "("
identifier "buf"
) ")"
- "-"
number_literal "1"
; ";"
if_statement
if "if"
condition_clause
( "("
binary_expression
parenthesized_expression any 2:1
( "(" any 2:1
binary_expression
call_expression
identifier "strlen"
argument_list
( "("
identifier "start_chars"
) ")"
< "<"
number_literal "1"
) ")" any 2:1
|| "||"
parenthesized_expression any 2:1
( "(" any 2:1
binary_expression
call_expression
identifier "strlen"
argument_list
( "("
identifier "start_chars"
) ")"
> ">"
identifier "size"
) ")" any 2:1
) ")"
compound_statement
{ "{"
throw_statement
throw "throw"
call_expression
qualified_identifier
namespace_identifier "std"
:: "::"
identifier "logic_error"
argument_list
( "("
string_literal
" "\""
string_content "InputSource::findSource called with too small or too large o"...
" "\""
) ")"
; ";"
} "}"
declaration
primitive_type "char"
init_declarator
pointer_declarator
* "*"
identifier "p"
= "="
null
nullptr "nullptr"
; ";"
declaration
type_identifier "qpdf_offset_t"
init_declarator
identifier "buf_offset"
= "="
identifier "offset"
; ";"
declaration
primitive_type "size_t"
init_declarator
identifier "bytes_read"
= "="
number_literal "0"
; ";"
comment "// Guarantee that we return from this loop. Each time throug"...
comment "// restart the loop with a condition that will cause return "...
comment "// either be out of range or hit EOF, either of which forces"...
while_statement (+597 nodes collapsed)
throw_statement
throw "throw"
call_expression
qualified_identifier
namespace_identifier "std"
:: "::"
identifier "logic_error"
argument_list
( "("
string_literal
" "\""
string_content "InputSource after while (true)"
" "\""
) ")"
; ";"
} "}"
function_definition (+192 nodes collapsed)

After

translation_unit
preproc_include
#include "#include"
system_lib_string "<qpdf/InputSource_private.hh>"
preproc_include
#include "#include"
system_lib_string "<qpdf/QIntC.hh>"
preproc_include
#include "#include"
system_lib_string "<qpdf/QTC.hh>"
preproc_include
#include "#include"
system_lib_string "<qpdf/Util.hh>"
preproc_include
#include "#include"
system_lib_string "<cstring>"
preproc_include
#include "#include"
system_lib_string "<stdexcept>"
using_declaration
using "using"
namespace "namespace"
qualified_identifier
namespace_identifier "std"
:: "::"
identifier "literals"
; ";"
using_declaration
using "using"
namespace "namespace"
identifier "qpdf"
; ";"
function_definition (+25 nodes collapsed)
function_definition (+22 nodes collapsed)
function_definition (+188 nodes collapsed)
function_definition (+28 nodes collapsed)
function_definition (+58 nodes collapsed)
function_definition
primitive_type "bool"
function_declarator (+29 nodes collapsed)
compound_statement
{ "{"
comment "// Basic approach: search for the first character of start_c"...
comment "// going past len (if len != 0). Once the first character is"...
comment "// of a sequence of characters matching start_chars. If so, "...
comment "// caller-specific additional checks. If not, keep searching"...
comment "// This code is tricky and highly subject to off-by-one or o"...
comment "// comments throughout that explain how we're not missing an"...
comment "// specifically constructed to make sure we caught the edge "...
declaration
primitive_type "char"
array_declarator
identifier "buf"
[ "["
number_literal "1025"
] "]"
; ";"
comment "// size known to input_source.cc in libtests"
comment "// To enable us to guarantee null-termination, save an extra"...
comment "// memory."
declaration
primitive_type "size_t"
init_declarator
identifier "size"
= "="
binary_expression
sizeof_expression
sizeof "sizeof"
parenthesized_expression
( "("
identifier "buf"
) ")"
- "-"
number_literal "1"
; ";"
expression_statement
call_expression
qualified_identifier
namespace_identifier "util"
:: "::"
identifier "assertion"
argument_list
( "("
unary_expression
! "!"
parenthesized_expression any 2:1
( "(" any 2:1
binary_expression
binary_expression
call_expression
identifier "strlen"
argument_list
( "("
identifier "start_chars"
) ")"
< "<"
number_literal "1"
|| "||"
binary_expression
call_expression
identifier "strlen"
argument_list
( "("
identifier "start_chars"
) ")"
> ">"
identifier "size"
) ")" any 2:1
, ","
string_literal
" "\""
string_content "InputSource::findSource called with too small or too large o"...
" "\""
comment "//"
) ")"
; ";"
declaration
primitive_type "char"
init_declarator
pointer_declarator
* "*"
identifier "p"
= "="
null
nullptr "nullptr"
; ";"
declaration
type_identifier "qpdf_offset_t"
init_declarator
identifier "buf_offset"
= "="
identifier "offset"
; ";"
declaration
primitive_type "size_t"
init_declarator
identifier "bytes_read"
= "="
number_literal "0"
; ";"
comment "// Guarantee that we return from this loop. Each time throug"...
comment "// restart the loop with a condition that will cause return "...
comment "// either be out of range or hit EOF, either of which forces"...
while_statement (+597 nodes collapsed)
} "}"
function_definition (+192 nodes collapsed)