Text   |  XML   |  ReML   |   Visible Warnings:

Redundant Condition  at mbox-sync-rewrite.c:256

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

mbox_sync_try_rewrite

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-storage/index/mbox/mbox-sync-rewrite.c)expand/collapse
Show more  
 242  int mbox_sync_try_rewrite(struct mbox_sync_mail_context *ctx, off_t move_diff)
 243  {
 244          struct mbox_sync_context *sync_ctx = ctx->sync_ctx;
 245          size_t old_hdr_size, new_hdr_size;
 246   
 247          i_assert(sync_ctx->mbox->mbox_lock_type == F_WRLCK);
 248   
 249          old_hdr_size = ctx->body_offset - ctx->hdr_offset;
 250          new_hdr_size = str_len(ctx->header);
 251   
 252          if (new_hdr_size <= old_hdr_size) {
 253                  /* add space. note that we must call add_space() even if we're
 254                     not adding anything so mail.offset gets fixed. */
 255                  mbox_sync_headers_add_space(ctx, old_hdr_size - new_hdr_size);
 256          } else if (new_hdr_size > old_hdr_size) {
 257                  /* try removing the space where we can */
 258                  mbox_sync_headers_remove_space(ctx,
 259                                                 new_hdr_size - old_hdr_size);
 260                  new_hdr_size = str_len(ctx->header);
 261   
 262                  if (new_hdr_size <= old_hdr_size) {
 263                          /* good, we removed enough. */
 264                          i_assert(new_hdr_size == old_hdr_size);
 265                  } else if (move_diff < 0 &&
 266                             new_hdr_size - old_hdr_size <= (uoff_t)-move_diff) {
 267                          /* moving backwards - we can use the extra space from 
 268                             it, just update expunged_space accordingly */
 269                          i_assert(ctx->mail.space == 0);
 270                          i_assert(sync_ctx->expunged_space >=
 271                                   (off_t)(new_hdr_size - old_hdr_size));
 272                          sync_ctx->expunged_space -= new_hdr_size - old_hdr_size;
 273                  } else {
 274                          /* couldn't get enough space */
 275                          i_assert(ctx->mail.space == 0);
 276                          ctx->mail.space =
 277                                  -(ssize_t)(new_hdr_size - old_hdr_size);
 278                          return 0;
 279                  }
 280          }
 281   
 282          i_assert(ctx->mail.space >= 0);
 283   
 284          if (ctx->header_first_change == (size_t)-1 && move_diff == 0) {
 285                  /* no changes actually. we get here if index sync record told
 286                     us to do something that was already there */
 287                  return 1;
 288          }
 289   
 290          if (move_diff != 0) {
 291                  /* forget about partial write optimizations */
 292                  ctx->header_first_change = 0;
 293                  ctx->header_last_change = 0;
 294          }
 295   
 296          if (ctx->header_last_change != (size_t)-1 &&
 297              ctx->header_last_change != 0)
 298                  str_truncate(ctx->header, ctx->header_last_change);
 299   
 300          if (pwrite_full(sync_ctx->write_fd,
 301                          str_data(ctx->header) + ctx->header_first_change,
 302                          str_len(ctx->header) - ctx->header_first_change,
 303                          ctx->hdr_offset + ctx->header_first_change +
 304                          move_diff) < 0) {
 305                  mbox_set_syscall_error(sync_ctx->mbox, "pwrite_full()");
 306                  return -1;
 307          }
 308   
 309          if (sync_ctx->dest_first_mail &&
 310              (ctx->imapbase_updated || ctx->sync_ctx->base_uid_last != 0)) {
 311                  /* the position might have moved as a result of moving
 312                     whitespace */
 313                  mbox_sync_first_mail_written(ctx, ctx->hdr_offset + move_diff);
 314          }
 315   
 316          mbox_sync_file_updated(sync_ctx, FALSE);
 317          return 1;
 318  }
Show more  




Change Warning 7404.24957 : Redundant Condition

Priority:
State:
Finding:
Owner:
Note: