mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
C API: qpdf_oh_is_initialized
This commit is contained in:
parent
bef2c2222a
commit
e3cc171d02
@ -1,5 +1,7 @@
|
||||
2021-12-02 Jay Berkenbilt <ejb@ql.org>
|
||||
|
||||
* C API: Add qpdf_oh_is_initialized.
|
||||
|
||||
* C API: Add qpdf_get_last_string_length to return the length of
|
||||
the last string returned. This is necessary in order to fully
|
||||
retrieve values of strings that may contain embedded null characters.
|
||||
|
@ -581,6 +581,8 @@ extern "C" {
|
||||
* to.
|
||||
*/
|
||||
|
||||
QPDF_DLL
|
||||
QPDF_BOOL qpdf_oh_is_initialized(qpdf_data data, qpdf_oh oh);
|
||||
QPDF_DLL
|
||||
QPDF_BOOL qpdf_oh_is_bool(qpdf_data data, qpdf_oh oh);
|
||||
QPDF_DLL
|
||||
|
@ -881,8 +881,7 @@ qpdf_oh_valid_internal(qpdf_data qpdf, qpdf_oh oh)
|
||||
{
|
||||
auto i = qpdf->oh_cache.find(oh);
|
||||
bool result = ((i != qpdf->oh_cache.end()) &&
|
||||
(i->second).getPointer() &&
|
||||
(i->second)->isInitialized());
|
||||
(i->second).getPointer());
|
||||
if (! result)
|
||||
{
|
||||
QTC::TC("qpdf", "qpdf-c invalid object handle");
|
||||
@ -892,11 +891,18 @@ qpdf_oh_valid_internal(qpdf_data qpdf, qpdf_oh oh)
|
||||
qpdf->qpdf->getFilename(),
|
||||
std::string("C API object handle ") +
|
||||
QUtil::uint_to_string(oh),
|
||||
0, "attempted access to unknown/uninitialized object handle"));
|
||||
0, "attempted access to unknown object handle"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QPDF_BOOL qpdf_oh_is_initialized(qpdf_data qpdf, qpdf_oh oh)
|
||||
{
|
||||
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_initialized");
|
||||
return (qpdf_oh_valid_internal(qpdf, oh) &&
|
||||
qpdf->oh_cache[oh]->isInitialized());
|
||||
}
|
||||
|
||||
QPDF_BOOL qpdf_oh_is_bool(qpdf_data qpdf, qpdf_oh oh)
|
||||
{
|
||||
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_bool");
|
||||
|
@ -5133,6 +5133,13 @@ print "\n";
|
||||
embedded null characters.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
Add <function>qpdf_oh_is_initialized</function> to the
|
||||
C API. While you can't directly create uninitialized objects
|
||||
from the C API, you still have to be able to detect them.
|
||||
</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
|
@ -512,6 +512,7 @@ static void test24(char const* infile,
|
||||
qpdf_oh_get_object_id(qpdf, root_from_trailer));
|
||||
qpdf_oh pages = qpdf_oh_get_key(qpdf, root, "/Pages");
|
||||
assert(qpdf_oh_is_dictionary(qpdf, pages));
|
||||
assert(qpdf_oh_is_initialized(qpdf, pages));
|
||||
qpdf_oh kids = qpdf_oh_get_key(qpdf, pages, "/Kids");
|
||||
assert(qpdf_oh_is_array(qpdf, kids));
|
||||
assert(qpdf_oh_get_array_n_items(qpdf, kids) == 1);
|
||||
@ -687,6 +688,12 @@ static void test24(char const* infile,
|
||||
qpdf_set_suppress_original_object_IDs(qpdf, QPDF_TRUE);
|
||||
qpdf_write(qpdf);
|
||||
report_errors();
|
||||
|
||||
/* Make sure we detect uninitialized objects */
|
||||
qpdf_data qpdf2 = qpdf_init();
|
||||
trailer = qpdf_get_trailer(qpdf2);
|
||||
assert(! qpdf_oh_is_initialized(qpdf2, trailer));
|
||||
qpdf_cleanup(&qpdf2);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
|
@ -600,3 +600,4 @@ QPDF_pages findPage not found 0
|
||||
qpdf overlay page with no resources 0
|
||||
QPDFObjectHandle check ownership 0
|
||||
qpdf weak crypto warning 0
|
||||
qpdf-c called qpdf_oh_is_initialized 0
|
||||
|
@ -7,18 +7,18 @@ item 0: 0 0.00
|
||||
item 1: 0 0.00
|
||||
item 2: 612 612.00
|
||||
item 3: 792 792.00
|
||||
warning: minimal.pdf (C API object handle 6): attempted access to unknown/uninitialized object handle
|
||||
warning: minimal.pdf (C API object handle 6): attempted access to unknown object handle
|
||||
code: 5
|
||||
file: minimal.pdf
|
||||
pos : 0
|
||||
text: attempted access to unknown/uninitialized object handle
|
||||
warning: minimal.pdf (C API object handle 9): attempted access to unknown/uninitialized object handle
|
||||
text: attempted access to unknown object handle
|
||||
warning: minimal.pdf (C API object handle 9): attempted access to unknown object handle
|
||||
code: 5
|
||||
file: minimal.pdf
|
||||
pos : 0
|
||||
text: attempted access to unknown/uninitialized object handle
|
||||
warning: minimal.pdf (C API object handle 9): attempted access to unknown/uninitialized object handle
|
||||
text: attempted access to unknown object handle
|
||||
warning: minimal.pdf (C API object handle 9): attempted access to unknown object handle
|
||||
code: 5
|
||||
file: minimal.pdf
|
||||
pos : 0
|
||||
text: attempted access to unknown/uninitialized object handle
|
||||
text: attempted access to unknown object handle
|
||||
|
Loading…
Reference in New Issue
Block a user