Skip to content

Commit

Permalink
Fine-Tune
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddenalpha committed Nov 22, 2024
1 parent ce5e376 commit d0dc0ad
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/main/cpp/_nix_based/jssc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,18 +662,23 @@ JNIEXPORT jbyteArray JNICALL Java_jssc_SerialNativeInterface_readBytes
int byteRemains = byteCount;

if( byteCount < 0 ){
char emsg[32]; emsg[0] = '\0';
snprintf(emsg, sizeof emsg, "new byte[%d]", byteCount);
jclass exClz = env->FindClass("java/lang/IllegalArgumentException");
char emsg[48];
err = snprintf(emsg, sizeof emsg, "Negative byteCount useless: %d", byteCount);
if( exClz != NULL && err > 0 ) env->ThrowNew(exClz, emsg);
if( exClz != NULL ) env->ThrowNew(exClz, emsg);
returnArray = NULL; goto Finally;
}
lpBuffer = new jbyte[byteCount];

try{
lpBuffer = new jbyte[byteCount];
}catch( const std::bad_alloc& ex ){
lpBuffer = NULL;
}
if( lpBuffer == NULL ){
char emsg[32]; emsg[0] = '\0';
snprintf(emsg, sizeof emsg, "new byte[%d]", byteCount);
jclass exClz = env->FindClass("java/lang/OutOfMemoryError");
char emsg[32];
err = snprintf(emsg, sizeof emsg, "new byte[%d]", byteCount);
if( exClz != NULL && err > 0 ) env->ThrowNew(exClz, emsg);
if( exClz != NULL ) env->ThrowNew(exClz, emsg);
returnArray = NULL; goto Finally;
}

Expand Down

0 comments on commit d0dc0ad

Please sign in to comment.