Skip to content

Commit

Permalink
Fixing for Clipboard-Agent Coverity issues
Browse files Browse the repository at this point in the history
Coverity scan reported
exn_spec_violation An exception of type std::length_error

Test done: Boot and Functional test passed with engineering build.

Tracked-On: OAM-112451
Signed-off-by: Reddy, Alavala Srinivasa <alavala.srinivasa.reddy@intel.com>
  • Loading branch information
alavalas1 committed Nov 16, 2023
1 parent dd9b055 commit c692c94
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions jni/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ cc_library_shared {
"-Werror",
"-Wno-unused-parameter",
"-Wno-unused-label",
"-fexceptions"
],
shared_libs: ["liblog"],
static_libs: ["libbase_ndk"],
Expand Down
20 changes: 16 additions & 4 deletions jni/DispatchHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "DispatchHelper.h"
#include <string.h>
#include <jni.h>
#include "android/log.h"

using namespace vsock;
std::map< std::string, std::vector<MSG_TYPE> > comp_msg_map {
Expand Down Expand Up @@ -66,12 +67,23 @@ class JavaComponent:public Component {
private:
jclass GetJClass() {
std::map< std::string, jclass >::iterator it;
jclass reqClass = nullptr;
it = jclass_map.find(java_class_name.c_str());
jclass reqClass = nullptr;
try
{
// Coverity fix: The following code may throw an exception of type std::length_error.
it = jclass_map.find(java_class_name.c_str());
if (it != jclass_map.end()) {
reqClass = it->second;
}
return reqClass;
}
}
catch (const std::exception& e)
{
// Coverity fix: GetJClass (typically used to report errors) may throw an
// exception of type std::length_error.
LOG(INFO) << "WARNING:GetJClass throw an exception" << e.what() << std::endl;
}
return reqClass;

}

jobject GetSingletonInstance(jclass reqClass) {
Expand Down

0 comments on commit c692c94

Please sign in to comment.