ENGINE-451: fixed compilation errors ENGINE-451
authorKrista Bennett <krista@pep-project.org>
Tue, 14 Aug 2018 08:08:11 +0200
branchENGINE-451
changeset 282046428521d2a8
parent 2819 666ce24696de
child 2822 a33bdd73952a
ENGINE-451: fixed compilation errors
src/pgp_gpg.c
     1.1 --- a/src/pgp_gpg.c	Tue Aug 14 07:51:44 2018 +0200
     1.2 +++ b/src/pgp_gpg.c	Tue Aug 14 08:08:11 2018 +0200
     1.3 @@ -30,12 +30,12 @@
     1.4      static char buf[MAX_LINELENGTH];
     1.5      size_t num_keys = stringlist_length(keys);
     1.6  
     1.7 -    // This function does:
     1.8 -    // 1. find a non-existent backup name numbered from 0 to 99 (otherwise fails)
     1.9 -    // 2. read the original file and meanwhile write the backup copy
    1.10 -    // 3. write the new config file to a temporary file in the same directory
    1.11 -    // 4. rename the temp file replacing the original config file
    1.12 -    // 5. on Windows remove the left-overs
    1.13 +    // This function:
    1.14 +    // 1. finds a non-existent backup name numbered from 0 to 99 (otherwise fails)
    1.15 +    // 2. reads the original file and meanwhiles write the backup copy
    1.16 +    // 3. writes the new config file to a temporary file in the same directory
    1.17 +    // 4. renames the temp file replacing the original config file
    1.18 +    // 5. on Windows removes the left-overs
    1.19  
    1.20      /* Find a suitable backup file name, without trashing previous ones */
    1.21      char* backup_file_path = NULL;
    1.22 @@ -52,7 +52,7 @@
    1.23      FILE *temp_config_file;
    1.24      stringlist_t* cur_string;
    1.25      bool status = false;
    1.26 -
    1.27 +    str_ptr_and_bit* found_keys = NULL;
    1.28  #ifdef WIN32
    1.29      WIN32_FIND_DATA FindFileData;
    1.30      HANDLE handle;
    1.31 @@ -89,7 +89,7 @@
    1.32  #else
    1.33          backup_file = Fopen(backup_file_path, "wbx");    // the 'x' is important
    1.34  #endif
    1.35 -        if (backup_file <= 0) {
    1.36 +        if (!backup_file) {
    1.37              free(backup_file_path);
    1.38              backup_file_path = NULL;
    1.39              continue;
    1.40 @@ -100,7 +100,7 @@
    1.41      if (!backup_file_path)
    1.42          goto quickfix_error;
    1.43  
    1.44 -    if (backup_file <= 0)
    1.45 +    if (!backup_file)
    1.46          goto quickfix_error;
    1.47  
    1.48      // Open original file, parse it, and meanwhile write a backup copy
    1.49 @@ -117,7 +117,7 @@
    1.50      // Go through every line in the file
    1.51      while ((s = Fgets(buf, MAX_LINELENGTH, f))) {
    1.52          // pointers to the keys found in this string
    1.53 -        str_ptr_and_bit* found_keys = (str_ptr_and_bit*)(calloc(num_keys, sizeof(str_ptr_and_bit)));
    1.54 +        found_keys = (str_ptr_and_bit*)(calloc(num_keys, sizeof(str_ptr_and_bit)));
    1.55          int num_found_keys = 0;
    1.56  
    1.57          ret = Fprintf(backup_file, "%s", s);
    1.58 @@ -297,13 +297,15 @@
    1.59          goto quickfix_error;
    1.60  
    1.61      // 2. Write the new config file to a temporary file in the same directory
    1.62 -
    1.63 -    assert(backup_file_path_baselen != NULL);
    1.64 +    assert(backup_file_path_baselen > 0);
    1.65 +    if (backup_file_path_baselen <= 0)
    1.66 +        goto quickfix_error;
    1.67  
    1.68      temp_config_file_path = (char*)calloc(backup_file_path_baselen + 8, 1);  // .XXXXXX\0
    1.69      ret = snprintf(temp_config_file_path, backup_file_path_baselen + 8, "%s.XXXXXX", config_file_path);
    1.70 -    assert(ret == NULL);
    1.71 -    if (!ret)
    1.72 +    assert(ret >= 0);
    1.73 +
    1.74 +    if (ret < 0)
    1.75          goto quickfix_error;
    1.76  
    1.77      int temp_config_filedesc = Mkstemp(temp_config_file_path);