[Libreoffice-commits] core.git: 3 commits - desktop/source include/LibreOfficeKit smoketest/libtest.cxx
Michael Meeks
michael.meeks at collabora.com
Thu Jun 12 06:06:53 PDT 2014
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 202dac6e20f75e87edab3368bb0882d59494d864
Author: Michael Meeks <michael.meeks at 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 4ed5bacc86e0137d9ace5a2ceda09c2393716793
Author: Michael Meeks <michael.meeks at 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 f24f4f92ee37401abf117f5cf3a8a224f39214aa
Author: Andrzej Hunt <andrzej.hunt at 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" );
More information about the Libreoffice-commits
mailing list