Fix memory corruption in the aiGetExportFormatDescription() API. Clarify Exporter doc.

pull/363/head
Alexander Gessler 2014-06-17 16:10:55 +02:00
parent 75fd29ac19
commit be5fc42e16
3 changed files with 21 additions and 2 deletions

View File

@ -61,6 +61,8 @@ ASSIMP_API size_t aiGetExportFormatCount(void)
// ------------------------------------------------------------------------------------------------
ASSIMP_API const aiExportFormatDesc* aiGetExportFormatDescription( size_t pIndex)
{
// Note: this is valid as the index always pertains to a builtin exporter,
// for which the returned structure is guaranteed to be of static storage duration.
return Exporter().GetExportFormatDescription(pIndex);
}

View File

@ -437,6 +437,11 @@ const aiExportFormatDesc* Exporter :: GetExportFormatDescription( size_t pIndex
return NULL;
}
// Return from static storage if the requested index is built-in.
if (pIndex < sizeof(gExporters) / sizeof(gExporters[0])) {
return &gExporters[pIndex].mDescription;
}
return &pimpl->mExporters[pIndex].mDescription;
}

View File

@ -251,7 +251,11 @@ public:
// -------------------------------------------------------------------
/** Returns the number of export file formats available in the current
* Assimp build. Use #Exporter::GetExportFormatDescription to
* retrieve infos of a specific export format */
* retrieve infos of a specific export format.
*
* This includes built-in exporters as well as exporters registered
* using #RegisterExporter.
**/
size_t GetExportFormatCount() const;
@ -259,6 +263,12 @@ public:
/** Returns a description of the nth export file format. Use #
* #Exporter::GetExportFormatCount to learn how many export
* formats are supported.
*
* The returned pointer is of static storage duration iff the
* pIndex pertains to a built-in exporter (i.e. one not registered
* via #RegistrerExporter). It is restricted to the life-time of the
* #Exporter instance otherwise.
*
* @param pIndex Index of the export format to retrieve information
* for. Valid range is 0 to #Exporter::GetExportFormatCount
* @return A description of that specific export format.
@ -269,7 +279,9 @@ public:
// -------------------------------------------------------------------
/** Register a custom exporter. Custom export formats are limited to
* to the current #Exporter instance and do not affect the
* library globally.
* library globally. The indexes under which the format's
* export format description can be queried are assigned
* monotonously.
* @param desc Exporter description.
* @return aiReturn_SUCCESS if the export format was successfully
* registered. A common cause that would prevent an exporter