musikr: fix segfault from logging nullptr
This commit is contained in:
parent
1fc9ca5147
commit
fe770337e6
1 changed files with 20 additions and 18 deletions
|
@ -30,7 +30,9 @@
|
|||
#include "taglib/vorbisfile.h"
|
||||
#include "taglib/wavfile.h"
|
||||
|
||||
bool parseMpeg(const char *name, TagLib::File *file,
|
||||
|
||||
|
||||
bool parseMpeg(const std::string &name, TagLib::File *file,
|
||||
JMetadataBuilder &jBuilder) {
|
||||
auto *mpegFile = dynamic_cast<TagLib::MPEG::File*>(file);
|
||||
if (mpegFile == nullptr) {
|
||||
|
@ -41,7 +43,7 @@ bool parseMpeg(const char *name, TagLib::File *file,
|
|||
try {
|
||||
jBuilder.setId3v1(*id3v1Tag);
|
||||
} catch (std::exception &e) {
|
||||
LOGE("Unable to parse ID3v1 tag in %s: %s", name, e.what());
|
||||
LOGE("Unable to parse ID3v1 tag in %s: %s", name.c_str(), e.what());
|
||||
}
|
||||
}
|
||||
auto id3v2Tag = mpegFile->ID3v2Tag();
|
||||
|
@ -49,13 +51,13 @@ bool parseMpeg(const char *name, TagLib::File *file,
|
|||
try {
|
||||
jBuilder.setId3v2(*id3v2Tag);
|
||||
} catch (std::exception &e) {
|
||||
LOGE("Unable to parse ID3v2 tag in %s: %s", name, e.what());
|
||||
LOGE("Unable to parse ID3v2 tag in %s: %s", name.c_str(), e.what());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parseMp4(const char *name, TagLib::File *file,
|
||||
bool parseMp4(const std::string &name, TagLib::File *file,
|
||||
JMetadataBuilder &jBuilder) {
|
||||
auto *mp4File = dynamic_cast<TagLib::MP4::File*>(file);
|
||||
if (mp4File == nullptr) {
|
||||
|
@ -66,13 +68,13 @@ bool parseMp4(const char *name, TagLib::File *file,
|
|||
try {
|
||||
jBuilder.setMp4(*tag);
|
||||
} catch (std::exception &e) {
|
||||
LOGE("Unable to parse MP4 tag in %s: %s", name, e.what());
|
||||
LOGE("Unable to parse MP4 tag in %s: %s", name.c_str(), e.what());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parseFlac(const char *name, TagLib::File *file,
|
||||
bool parseFlac(const std::string &name, TagLib::File *file,
|
||||
JMetadataBuilder &jBuilder) {
|
||||
auto *flacFile = dynamic_cast<TagLib::FLAC::File*>(file);
|
||||
if (flacFile == nullptr) {
|
||||
|
@ -83,7 +85,7 @@ bool parseFlac(const char *name, TagLib::File *file,
|
|||
try {
|
||||
jBuilder.setId3v1(*id3v1Tag);
|
||||
} catch (std::exception &e) {
|
||||
LOGE("Unable to parse ID3v1 tag in %s: %s", name, e.what());
|
||||
LOGE("Unable to parse ID3v1 tag in %s: %s", name.c_str(), e.what());
|
||||
}
|
||||
}
|
||||
auto id3v2Tag = flacFile->ID3v2Tag();
|
||||
|
@ -91,7 +93,7 @@ bool parseFlac(const char *name, TagLib::File *file,
|
|||
try {
|
||||
jBuilder.setId3v2(*id3v2Tag);
|
||||
} catch (std::exception &e) {
|
||||
LOGE("Unable to parse ID3v2 tag in %s: %s", name, e.what());
|
||||
LOGE("Unable to parse ID3v2 tag in %s: %s", name.c_str(), e.what());
|
||||
}
|
||||
}
|
||||
auto xiphComment = flacFile->xiphComment();
|
||||
|
@ -99,7 +101,7 @@ bool parseFlac(const char *name, TagLib::File *file,
|
|||
try {
|
||||
jBuilder.setXiph(*xiphComment);
|
||||
} catch (std::exception &e) {
|
||||
LOGE("Unable to parse Xiph comment in %s: %s", name, e.what());
|
||||
LOGE("Unable to parse Xiph comment in %s: %s", name.c_str(), e.what());
|
||||
}
|
||||
}
|
||||
auto pics = flacFile->pictureList();
|
||||
|
@ -107,7 +109,7 @@ bool parseFlac(const char *name, TagLib::File *file,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool parseOpus(const char *name, TagLib::File *file,
|
||||
bool parseOpus(const std::string &name, TagLib::File *file,
|
||||
JMetadataBuilder &jBuilder) {
|
||||
auto *opusFile = dynamic_cast<TagLib::Ogg::Opus::File*>(file);
|
||||
if (opusFile == nullptr) {
|
||||
|
@ -118,13 +120,13 @@ bool parseOpus(const char *name, TagLib::File *file,
|
|||
try {
|
||||
jBuilder.setXiph(*tag);
|
||||
} catch (std::exception &e) {
|
||||
LOGE("Unable to parse Xiph comment in %s: %s", name, e.what());
|
||||
LOGE("Unable to parse Xiph comment in %s: %s", name.c_str(), e.what());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parseVorbis(const char *name, TagLib::File *file,
|
||||
bool parseVorbis(const std::string &name, TagLib::File *file,
|
||||
JMetadataBuilder &jBuilder) {
|
||||
auto *vorbisFile = dynamic_cast<TagLib::Ogg::Vorbis::File*>(file);
|
||||
if (vorbisFile == nullptr) {
|
||||
|
@ -135,13 +137,13 @@ bool parseVorbis(const char *name, TagLib::File *file,
|
|||
try {
|
||||
jBuilder.setXiph(*tag);
|
||||
} catch (std::exception &e) {
|
||||
LOGE("Unable to parse Xiph comment %s: %s", name, e.what());
|
||||
LOGE("Unable to parse Xiph comment %s: %s", name.c_str(), e.what());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parseWav(const char *name, TagLib::File *file,
|
||||
bool parseWav(const std::string &name, TagLib::File *file,
|
||||
JMetadataBuilder &jBuilder) {
|
||||
auto *wavFile = dynamic_cast<TagLib::RIFF::WAV::File*>(file);
|
||||
if (wavFile == nullptr) {
|
||||
|
@ -152,7 +154,7 @@ bool parseWav(const char *name, TagLib::File *file,
|
|||
try {
|
||||
jBuilder.setId3v2(*tag);
|
||||
} catch (std::exception &e) {
|
||||
LOGE("Unable to parse ID3v2 tag in %s: %s", name, e.what());
|
||||
LOGE("Unable to parse ID3v2 tag in %s: %s", name.c_str(), e.what());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -162,7 +164,7 @@ extern "C" JNIEXPORT jobject JNICALL
|
|||
Java_org_oxycblt_musikr_metadata_TagLibJNI_openNative(JNIEnv *env,
|
||||
jobject /* this */,
|
||||
jobject inputStream) {
|
||||
const char *name = nullptr;
|
||||
std::string name = "unknown file";
|
||||
try {
|
||||
JInputStream jStream {env, inputStream};
|
||||
name = jStream.name();
|
||||
|
@ -189,12 +191,12 @@ Java_org_oxycblt_musikr_metadata_TagLibJNI_openNative(JNIEnv *env,
|
|||
} else if (parseWav(name, file, jBuilder)) {
|
||||
jBuilder.setMimeType("audio/wav");
|
||||
} else {
|
||||
LOGE("File format in %s is not supported", name);
|
||||
LOGE("File format in %s is not supported", name.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
return jBuilder.build();
|
||||
} catch (std::exception &e) {
|
||||
LOGE("Unable to parse metadata in %s: %s", name != nullptr ? name : "unknown file", e.what());
|
||||
LOGE("Unable to parse metadata in %s: %s", name.c_str(), e.what());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue