comparison src/memline.c @ 31728:238ca27dbfd2 v9.0.1196

patch 9.0.1196: code is indented more than necessary Commit: https://github.com/vim/vim/commit/e8575988969579f9e1439181ae338b2ff74054a8 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sat Jan 14 12:32:28 2023 +0000 patch 9.0.1196: code is indented more than necessary Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes #11813)
author Bram Moolenaar <Bram@vim.org>
date Sat, 14 Jan 2023 13:45:04 +0100
parents 2536ffb8fc37
children 9f28cca2410a
comparison
equal deleted inserted replaced
31727:2b50a7f0feec 31728:238ca27dbfd2
420 * Prepare encryption for "buf" for the current key and method. 420 * Prepare encryption for "buf" for the current key and method.
421 */ 421 */
422 static void 422 static void
423 ml_set_mfp_crypt(buf_T *buf) 423 ml_set_mfp_crypt(buf_T *buf)
424 { 424 {
425 if (*buf->b_p_key != NUL) 425 if (*buf->b_p_key == NUL)
426 { 426 return;
427 int method_nr = crypt_get_method_nr(buf); 427
428 428 int method_nr = crypt_get_method_nr(buf);
429 if (method_nr > CRYPT_M_ZIP && method_nr < CRYPT_M_SOD) 429
430 { 430 if (method_nr > CRYPT_M_ZIP && method_nr < CRYPT_M_SOD)
431 // Generate a seed and store it in the memfile. 431 {
432 sha2_seed(buf->b_ml.ml_mfp->mf_seed, MF_SEED_LEN, NULL, 0); 432 // Generate a seed and store it in the memfile.
433 } 433 sha2_seed(buf->b_ml.ml_mfp->mf_seed, MF_SEED_LEN, NULL, 0);
434 }
434 #ifdef FEAT_SODIUM 435 #ifdef FEAT_SODIUM
435 else if (method_nr == CRYPT_M_SOD) 436 else if (method_nr == CRYPT_M_SOD)
436 crypt_sodium_randombytes_buf(buf->b_ml.ml_mfp->mf_seed, 437 crypt_sodium_randombytes_buf(buf->b_ml.ml_mfp->mf_seed,
437 MF_SEED_LEN); 438 MF_SEED_LEN);
438 #endif 439 #endif
439 }
440 } 440 }
441 441
442 /* 442 /*
443 * Prepare encryption for "buf" with block 0 "b0p". 443 * Prepare encryption for "buf" with block 0 "b0p".
444 */ 444 */
2088 make_percent_swname(char_u *dir, char_u *name) 2088 make_percent_swname(char_u *dir, char_u *name)
2089 { 2089 {
2090 char_u *d = NULL, *s, *f; 2090 char_u *d = NULL, *s, *f;
2091 2091
2092 f = fix_fname(name != NULL ? name : (char_u *)""); 2092 f = fix_fname(name != NULL ? name : (char_u *)"");
2093 if (f != NULL) 2093 if (f == NULL)
2094 { 2094 return NULL;
2095 s = alloc(STRLEN(f) + 1); 2095
2096 if (s != NULL) 2096 s = alloc(STRLEN(f) + 1);
2097 { 2097 if (s != NULL)
2098 STRCPY(s, f); 2098 {
2099 for (d = s; *d != NUL; MB_PTR_ADV(d)) 2099 STRCPY(s, f);
2100 if (vim_ispathsep(*d)) 2100 for (d = s; *d != NUL; MB_PTR_ADV(d))
2101 *d = '%'; 2101 if (vim_ispathsep(*d))
2102 2102 *d = '%';
2103 dir[STRLEN(dir) - 1] = NUL; // remove one trailing slash 2103
2104 d = concat_fnames(dir, s, TRUE); 2104 dir[STRLEN(dir) - 1] = NUL; // remove one trailing slash
2105 vim_free(s); 2105 d = concat_fnames(dir, s, TRUE);
2106 } 2106 vim_free(s);
2107 vim_free(f); 2107 }
2108 } 2108 vim_free(f);
2109 return d; 2109 return d;
2110 } 2110 }
2111 #endif 2111 #endif
2112 2112
2113 #if (defined(UNIX) || defined(VMS) || defined(MSWIN)) \ 2113 #if (defined(UNIX) || defined(VMS) || defined(MSWIN)) \
5471 char_u *head_end; 5471 char_u *head_end;
5472 char_u *text_start; 5472 char_u *text_start;
5473 int text_len; 5473 int text_len;
5474 cryptstate_T *state; 5474 cryptstate_T *state;
5475 5475
5476 if (dp->db_id == DATA_ID) 5476 if (dp->db_id != DATA_ID)
5477 { 5477 return;
5478 head_end = (char_u *)(&dp->db_index[dp->db_line_count]); 5478
5479 text_start = (char_u *)dp + dp->db_txt_start; 5479 head_end = (char_u *)(&dp->db_index[dp->db_line_count]);
5480 text_len = dp->db_txt_end - dp->db_txt_start; 5480 text_start = (char_u *)dp + dp->db_txt_start;
5481 5481 text_len = dp->db_txt_end - dp->db_txt_start;
5482 if (head_end > text_start || dp->db_txt_start > size 5482
5483 || dp->db_txt_end > size) 5483 if (head_end > text_start || dp->db_txt_start > size
5484 return; // data was messed up 5484 || dp->db_txt_end > size)
5485 5485 return; // data was messed up
5486 state = ml_crypt_prepare(mfp, offset, TRUE); 5486
5487 if (state != NULL) 5487 state = ml_crypt_prepare(mfp, offset, TRUE);
5488 { 5488 if (state == NULL)
5489 // Decrypt the text in place. 5489 return;
5490 crypt_decode_inplace(state, text_start, text_len, FALSE); 5490
5491 crypt_free_state(state); 5491 // Decrypt the text in place.
5492 } 5492 crypt_decode_inplace(state, text_start, text_len, FALSE);
5493 } 5493 crypt_free_state(state);
5494 } 5494 }
5495 5495
5496 /* 5496 /*
5497 * Prepare for encryption/decryption, using the key, seed and offset. 5497 * Prepare for encryption/decryption, using the key, seed and offset.
5498 * Return an allocated cryptstate_T *. 5498 * Return an allocated cryptstate_T *.