coverity/75594: Explicit null dereferenced: RI.

Problem    : Exlicit null dereferenced (FORWARD NULL) @ 2859.
Diagnostic : Real issue.
Rationale  : Code within `if (!p_bk)` seems to assume `backup` not null
             at that point, which may not be true.
Resolution : Don't enter conditional on null `backup`.
This commit is contained in:
Eliseo Martínez 2014-12-16 13:37:56 +01:00
parent 85ee4b83ac
commit e0b23b3d09

View File

@ -2839,27 +2839,25 @@ buf_write (
* Check if backup file already exists.
*/
if (os_fileinfo((char *)backup, &file_info_new)) {
/*
* Check if backup file is same as original file.
* May happen when modname() gave the same file back (e.g. silly
* link). If we don't check here, we either ruin the file when
* copying or erase it after writing.
*/
if (os_fileinfo_id_equal(&file_info_new, &file_info_old)) {
/*
* Backup file is same as original file.
* May happen when modname() gave the same file back (e.g. silly
* link). If we don't check here, we either ruin the file when
* copying or erase it after writing.
*/
free(backup);
backup = NULL; /* no backup file to delete */
}
/*
* If we are not going to keep the backup file, don't
* delete an existing one, try to use another name.
* Change one character, just before the extension.
*/
if (!p_bk) {
wp = backup + STRLEN(backup) - 1
- STRLEN(backup_ext);
if (wp < backup) /* empty file name ??? */
} else if (!p_bk) {
/*
* We are not going to keep the backup file, so don't
* delete an existing one, and try to use another name instead.
* Change one character, just before the extension.
*/
wp = backup + STRLEN(backup) - 1 - STRLEN(backup_ext);
if (wp < backup) { /* empty file name ??? */
wp = backup;
}
*wp = 'z';
while (*wp > 'a'
&& os_fileinfo((char *)backup, &file_info_new)) {