Changeset 35700


Ignore:
Timestamp:
2021-10-25T00:39:08+13:00 (2 years ago)
Author:
davidb
Message:

Some additional checking added in

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/search4j/libsearch4j.cpp

    r35699 r35700  
    342342char* get_dirname (const char* full_file_path)
    343343{
    344   char* full_file_path_dup = strdup(full_file_path);
     344  char* parent_dir = NULL;
     345 
     346  if (full_file_path != NULL) {
     347 
     348    char* full_file_path_dup = strdup(full_file_path);
    345349#ifdef WINDOWS
    346   char *p = strrchr(full_file_path_dup, '\\');
     350    char *p = strrchr(full_file_path_dup, '\\');
    347351#else
    348   char *p = strrchr(full_file_path_dup, '/');
     352    char *p = strrchr(full_file_path_dup, '/');
    349353#endif
    350354
    351   if (p != NULL) {
    352     p[0] = 0;
     355    if (p != NULL) {
     356      // truncate the string at the point where the dir-separator was found
     357      p[0] = 0;
     358      parent_dir = full_file_path_dup;
     359    }
     360    else {
     361      // no dir-separator found
     362      free(full_file_path_dup);
     363      full_file_path_dup = NULL;
     364    }
    353365  }
    354    
    355   return full_file_path_dup;
     366     
     367  return parent_dir;
    356368}
    357369
     
    578590
    579591          char* parent_dir = get_dirname(full_path_java);
    580           char* parent_parent_dir = get_dirname(parent_dir);
     592          char* parent_parent_dir = get_dirname(parent_dir); 
    581593         
    582594          javaHomeEnv = parent_parent_dir;
    583595
    584           free(parent_dir);
     596          if (parent_dir != NULL) {
     597            free(parent_dir);
     598          }
    585599         
    586600          // Logic from here same as for other search4j java/javac testing
    587           if ( verbose ) cout << "(" << javaHomeEnv << ") ";
    588           jvm.setJavaHome( javaHomeEnv );
    589           if ( jvm.check() ) {
    590             if ( use_minimum ) {
    591               if ( jvm.compare( minimum ) >= 0 ) {
     601          if (javaHomeEnv != NULL) {
     602            if ( verbose ) cout << "(" << javaHomeEnv << ") ";
     603            jvm.setJavaHome( javaHomeEnv );
     604            if ( jvm.check() ) {
     605              if ( use_minimum ) {
     606            if ( jvm.compare( minimum ) >= 0 ) {
     607              jvmFound = true;
     608            }
     609              } else {
    592610            jvmFound = true;
    593611              }
    594             } else {
    595               jvmFound = true;
    596612            }
     613            if ( (jreOnly && !jvm.getIsJre() ) || (jdkOnly && !jvm.getIsJdk()) ) {
     614              jvmFound = false;
     615            }         
    597616          }
    598           if ( (jreOnly && !jvm.getIsJre() ) || (jdkOnly && !jvm.getIsJdk()) ) {
    599             jvmFound = false;
    600           }
    601          
    602617        }
    603618        if ( verbose ) { if( jvmFound ) cout << "yes" << endl; else cout << "no" << endl; }
Note: See TracChangeset for help on using the changeset viewer.