desktop/source/lib/init.cxx | 4 ++-- include/LibreOfficeKit/LibreOfficeKit.h | 9 +++++++++ include/LibreOfficeKit/LibreOfficeKit.hxx | 8 ++++---- smoketest/libtest.cxx | 12 +++++++++++- 4 files changed, 26 insertions(+), 7 deletions(-)
New commits: commit 540eb29d08729a853d7405b3eb826e02c42c65b9 Author: Michael Meeks <michael.me...@collabora.com> Date: Thu Jun 12 13:28:26 2014 +0100 liblok: check new methods via macros on nSize, not by de-referencing. We can't check for NULL from beyond the end of a smaller structure. Change-Id: Id3754bf747c402cf0d767eda5fd4b5ad6b5789e9 diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index 97acbab..657c16c 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -18,6 +18,13 @@ extern "C" typedef struct _LibreOfficeKit LibreOfficeKit; typedef struct _LibreOfficeKitDocument LibreOfficeKitDocument; +// Do we have an extended member in this struct ? +#define LIBREOFFICEKIT_HAS_MEMBER(strct,member,nSize) \ + ((((int)((unsigned char *)&((strct *) 0)->member) + \ + (int)sizeof ((strct *) 0)->member)) <= (nSize)) + +#define LIBREOFFICEKIT_HAS(pKit,member) LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKit,member,(pKit)->nSize) + struct _LibreOfficeKit { int nSize; @@ -28,6 +35,8 @@ struct _LibreOfficeKit char* (*getError) (LibreOfficeKit *pThis); }; +#define LIBREOFFICEKIT_DOCUMENT_HAS(pDoc,member) LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKitDocument,member,(pDoc)->nSize) + struct _LibreOfficeKitDocument { int nSize; diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index 956e3cb..ec11313 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -45,11 +45,12 @@ public: inline bool saveAsWithOptions(const char* pUrl, const char* pFormat = NULL, const char* pFilterOptions = NULL) { // available since LibreOffice 4.3 - if (!mpDoc->saveAsWithOptions) + if (!LIBREOFFICEKIT_DOCUMENT_HAS(mpDoc, saveAsWithOptions)) return false; return mpDoc->saveAsWithOptions(mpDoc, pUrl, pFormat, pFilterOptions); } + inline LibreOfficeKitDocument *get() { return mpDoc; } }; class Office diff --git a/smoketest/libtest.cxx b/smoketest/libtest.cxx index 07a13ec..2316b8c 100644 --- a/smoketest/libtest.cxx +++ b/smoketest/libtest.cxx @@ -75,6 +75,16 @@ int main (int argc, char **argv) return -1; } + if (!LIBREOFFICEKIT_DOCUMENT_HAS(pDocument->get(), saveAsWithOptions)) + { + fprintf( stderr, "using obsolete LibreOffice %d + %d vs. %d\n", + (int)((unsigned char *)&((LibreOfficeKitDocument *) 0)->saveAsWithOptions), + (int)sizeof ((LibreOfficeKitDocument *) 0)->saveAsWithOptions, + pDocument->get()->nSize ); + return -1; + } + + end = getTimeMS(); fprintf( stderr, "load time: %ld ms\n", (end-start) ); start = end; commit 7de8049a17a0d2e11a2e298060bb5495d34d357d Author: Michael Meeks <michael.me...@collabora.com> Date: Thu Jun 12 13:27:27 2014 +0100 liblok: set the size for the correct structure. Change-Id: Id79d76893bfc931334afd59b05ab96a31e441e02 diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 512cfb3..af812c6 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -155,7 +155,7 @@ struct LibLODocument_Impl : public _LibreOfficeKitDocument LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent) : mxComponent( xComponent ) { - nSize = sizeof(LibreOfficeKit); + nSize = sizeof(LibreOfficeKitDocument); destroy = doc_destroy; saveAs = doc_saveAs; @@ -185,7 +185,7 @@ struct LibLibreOffice_Impl : public _LibreOfficeKit LibLibreOffice_Impl() { - nSize = sizeof(LibreOfficeKitDocument); + nSize = sizeof(LibreOfficeKit); destroy = lo_destroy; initialize = lo_initialize; commit 09e5df3991eeba4f6f4280514d466dc52e21bd29 Author: Andrzej Hunt <andrzej.h...@collabora.com> Date: Wed Jun 11 15:37:17 2014 +0100 Complete LibreOfficeKit C++ renaming. Change-Id: Ice611cf5913051346a3a0c0b00ed35a35a0dfe3c diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index c3da497..956e3cb 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -87,9 +87,7 @@ public: } }; -} - -inline ::lok::Office* lo_cpp_init(const char* pInstallPath) +inline Office* lok_cpp_init(const char* pInstallPath) { LibreOfficeKit* pThis = lok_init(pInstallPath); if (pThis == NULL || pThis->nSize == 0) @@ -97,5 +95,6 @@ inline ::lok::Office* lo_cpp_init(const char* pInstallPath) return new ::lok::Office(pThis); } +} #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/smoketest/libtest.cxx b/smoketest/libtest.cxx index c6211a9..07a13ec 100644 --- a/smoketest/libtest.cxx +++ b/smoketest/libtest.cxx @@ -46,7 +46,7 @@ int main (int argc, char **argv) return 1; } - Office *pOffice = lo_cpp_init( argv[1] ); + Office *pOffice = lok_cpp_init( argv[1] ); if( !pOffice ) { fprintf( stderr, "Failed to initialize\n" ); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits