Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0febea37 authored by Yi Kong's avatar Yi Kong Committed by android-build-merger
Browse files

Merge "[libsparse] Modernize codebase by replacing NULL with nullptr" am: 48e3cdef

am: d322a108

Change-Id: Ica9245ea78eaa6ececae02ff3f1df111fa8d8377
parents 17ae990f d322a108
Loading
Loading
Loading
Loading
+16 −16
Original line number Original line Diff line number Diff line
@@ -133,7 +133,7 @@ void backed_block_list_move(struct backed_block_list* from, struct backed_block_
                            struct backed_block* start, struct backed_block* end) {
                            struct backed_block* start, struct backed_block* end) {
  struct backed_block* bb;
  struct backed_block* bb;


  if (start == NULL) {
  if (start == nullptr) {
    start = from->data_blocks;
    start = from->data_blocks;
  }
  }


@@ -142,12 +142,12 @@ void backed_block_list_move(struct backed_block_list* from, struct backed_block_
      ;
      ;
  }
  }


  if (start == NULL || end == NULL) {
  if (start == nullptr || end == nullptr) {
    return;
    return;
  }
  }


  from->last_used = NULL;
  from->last_used = nullptr;
  to->last_used = NULL;
  to->last_used = nullptr;
  if (from->data_blocks == start) {
  if (from->data_blocks == start) {
    from->data_blocks = end->next;
    from->data_blocks = end->next;
  } else {
  } else {
@@ -161,7 +161,7 @@ void backed_block_list_move(struct backed_block_list* from, struct backed_block_


  if (!to->data_blocks) {
  if (!to->data_blocks) {
    to->data_blocks = start;
    to->data_blocks = start;
    end->next = NULL;
    end->next = nullptr;
  } else {
  } else {
    for (bb = to->data_blocks; bb; bb = bb->next) {
    for (bb = to->data_blocks; bb; bb = bb->next) {
      if (!bb->next || bb->next->block > start->block) {
      if (!bb->next || bb->next->block > start->block) {
@@ -230,7 +230,7 @@ static int merge_bb(struct backed_block_list* bbl, struct backed_block* a, struc
static int queue_bb(struct backed_block_list* bbl, struct backed_block* new_bb) {
static int queue_bb(struct backed_block_list* bbl, struct backed_block* new_bb) {
  struct backed_block* bb;
  struct backed_block* bb;


  if (bbl->data_blocks == NULL) {
  if (bbl->data_blocks == nullptr) {
    bbl->data_blocks = new_bb;
    bbl->data_blocks = new_bb;
    return 0;
    return 0;
  }
  }
@@ -253,7 +253,7 @@ static int queue_bb(struct backed_block_list* bbl, struct backed_block* new_bb)
  for (; bb->next && bb->next->block < new_bb->block; bb = bb->next)
  for (; bb->next && bb->next->block < new_bb->block; bb = bb->next)
    ;
    ;


  if (bb->next == NULL) {
  if (bb->next == nullptr) {
    bb->next = new_bb;
    bb->next = new_bb;
  } else {
  } else {
    new_bb->next = bb->next;
    new_bb->next = bb->next;
@@ -273,7 +273,7 @@ static int queue_bb(struct backed_block_list* bbl, struct backed_block* new_bb)
int backed_block_add_fill(struct backed_block_list* bbl, unsigned int fill_val, unsigned int len,
int backed_block_add_fill(struct backed_block_list* bbl, unsigned int fill_val, unsigned int len,
                          unsigned int block) {
                          unsigned int block) {
  struct backed_block* bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
  struct backed_block* bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
  if (bb == NULL) {
  if (bb == nullptr) {
    return -ENOMEM;
    return -ENOMEM;
  }
  }


@@ -281,7 +281,7 @@ int backed_block_add_fill(struct backed_block_list* bbl, unsigned int fill_val,
  bb->len = len;
  bb->len = len;
  bb->type = BACKED_BLOCK_FILL;
  bb->type = BACKED_BLOCK_FILL;
  bb->fill.val = fill_val;
  bb->fill.val = fill_val;
  bb->next = NULL;
  bb->next = nullptr;


  return queue_bb(bbl, bb);
  return queue_bb(bbl, bb);
}
}
@@ -290,7 +290,7 @@ int backed_block_add_fill(struct backed_block_list* bbl, unsigned int fill_val,
int backed_block_add_data(struct backed_block_list* bbl, void* data, unsigned int len,
int backed_block_add_data(struct backed_block_list* bbl, void* data, unsigned int len,
                          unsigned int block) {
                          unsigned int block) {
  struct backed_block* bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
  struct backed_block* bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
  if (bb == NULL) {
  if (bb == nullptr) {
    return -ENOMEM;
    return -ENOMEM;
  }
  }


@@ -298,7 +298,7 @@ int backed_block_add_data(struct backed_block_list* bbl, void* data, unsigned in
  bb->len = len;
  bb->len = len;
  bb->type = BACKED_BLOCK_DATA;
  bb->type = BACKED_BLOCK_DATA;
  bb->data.data = data;
  bb->data.data = data;
  bb->next = NULL;
  bb->next = nullptr;


  return queue_bb(bbl, bb);
  return queue_bb(bbl, bb);
}
}
@@ -307,7 +307,7 @@ int backed_block_add_data(struct backed_block_list* bbl, void* data, unsigned in
int backed_block_add_file(struct backed_block_list* bbl, const char* filename, int64_t offset,
int backed_block_add_file(struct backed_block_list* bbl, const char* filename, int64_t offset,
                          unsigned int len, unsigned int block) {
                          unsigned int len, unsigned int block) {
  struct backed_block* bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
  struct backed_block* bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
  if (bb == NULL) {
  if (bb == nullptr) {
    return -ENOMEM;
    return -ENOMEM;
  }
  }


@@ -316,7 +316,7 @@ int backed_block_add_file(struct backed_block_list* bbl, const char* filename, i
  bb->type = BACKED_BLOCK_FILE;
  bb->type = BACKED_BLOCK_FILE;
  bb->file.filename = strdup(filename);
  bb->file.filename = strdup(filename);
  bb->file.offset = offset;
  bb->file.offset = offset;
  bb->next = NULL;
  bb->next = nullptr;


  return queue_bb(bbl, bb);
  return queue_bb(bbl, bb);
}
}
@@ -325,7 +325,7 @@ int backed_block_add_file(struct backed_block_list* bbl, const char* filename, i
int backed_block_add_fd(struct backed_block_list* bbl, int fd, int64_t offset, unsigned int len,
int backed_block_add_fd(struct backed_block_list* bbl, int fd, int64_t offset, unsigned int len,
                        unsigned int block) {
                        unsigned int block) {
  struct backed_block* bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
  struct backed_block* bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
  if (bb == NULL) {
  if (bb == nullptr) {
    return -ENOMEM;
    return -ENOMEM;
  }
  }


@@ -334,7 +334,7 @@ int backed_block_add_fd(struct backed_block_list* bbl, int fd, int64_t offset, u
  bb->type = BACKED_BLOCK_FD;
  bb->type = BACKED_BLOCK_FD;
  bb->fd.fd = fd;
  bb->fd.fd = fd;
  bb->fd.offset = offset;
  bb->fd.offset = offset;
  bb->next = NULL;
  bb->next = nullptr;


  return queue_bb(bbl, bb);
  return queue_bb(bbl, bb);
}
}
@@ -350,7 +350,7 @@ int backed_block_split(struct backed_block_list* bbl, struct backed_block* bb,
  }
  }


  new_bb = reinterpret_cast<backed_block*>(malloc(sizeof(struct backed_block)));
  new_bb = reinterpret_cast<backed_block*>(malloc(sizeof(struct backed_block)));
  if (new_bb == NULL) {
  if (new_bb == nullptr) {
    return -ENOMEM;
    return -ENOMEM;
  }
  }


+9 −9
Original line number Original line Diff line number Diff line
@@ -233,7 +233,7 @@ static int gz_file_write(struct output_file* out, void* data, size_t len) {
  while (len > 0) {
  while (len > 0) {
    ret = gzwrite(outgz->gz_fd, data, min(len, (unsigned int)INT_MAX));
    ret = gzwrite(outgz->gz_fd, data, min(len, (unsigned int)INT_MAX));
    if (ret == 0) {
    if (ret == 0) {
      error("gzwrite %s", gzerror(outgz->gz_fd, NULL));
      error("gzwrite %s", gzerror(outgz->gz_fd, nullptr));
      return -1;
      return -1;
    }
    }
    len -= ret;
    len -= ret;
@@ -269,7 +269,7 @@ static int callback_file_skip(struct output_file* out, int64_t off) {


  while (off > 0) {
  while (off > 0) {
    to_write = min(off, (int64_t)INT_MAX);
    to_write = min(off, (int64_t)INT_MAX);
    ret = outc->write(outc->priv, NULL, to_write);
    ret = outc->write(outc->priv, nullptr, to_write);
    if (ret < 0) {
    if (ret < 0) {
      return ret;
      return ret;
    }
    }
@@ -568,7 +568,7 @@ static struct output_file* output_file_new_gz(void) {
      reinterpret_cast<struct output_file_gz*>(calloc(1, sizeof(struct output_file_gz)));
      reinterpret_cast<struct output_file_gz*>(calloc(1, sizeof(struct output_file_gz)));
  if (!outgz) {
  if (!outgz) {
    error_errno("malloc struct outgz");
    error_errno("malloc struct outgz");
    return NULL;
    return nullptr;
  }
  }


  outgz->out.ops = &gz_file_ops;
  outgz->out.ops = &gz_file_ops;
@@ -581,7 +581,7 @@ static struct output_file* output_file_new_normal(void) {
      reinterpret_cast<struct output_file_normal*>(calloc(1, sizeof(struct output_file_normal)));
      reinterpret_cast<struct output_file_normal*>(calloc(1, sizeof(struct output_file_normal)));
  if (!outn) {
  if (!outn) {
    error_errno("malloc struct outn");
    error_errno("malloc struct outn");
    return NULL;
    return nullptr;
  }
  }


  outn->out.ops = &file_ops;
  outn->out.ops = &file_ops;
@@ -599,7 +599,7 @@ struct output_file* output_file_open_callback(int (*write)(void*, const void*, s
      reinterpret_cast<struct output_file_callback*>(calloc(1, sizeof(struct output_file_callback)));
      reinterpret_cast<struct output_file_callback*>(calloc(1, sizeof(struct output_file_callback)));
  if (!outc) {
  if (!outc) {
    error_errno("malloc struct outc");
    error_errno("malloc struct outc");
    return NULL;
    return nullptr;
  }
  }


  outc->out.ops = &callback_file_ops;
  outc->out.ops = &callback_file_ops;
@@ -609,7 +609,7 @@ struct output_file* output_file_open_callback(int (*write)(void*, const void*, s
  ret = output_file_init(&outc->out, block_size, len, sparse, chunks, crc);
  ret = output_file_init(&outc->out, block_size, len, sparse, chunks, crc);
  if (ret < 0) {
  if (ret < 0) {
    free(outc);
    free(outc);
    return NULL;
    return nullptr;
  }
  }


  return &outc->out;
  return &outc->out;
@@ -626,7 +626,7 @@ struct output_file* output_file_open_fd(int fd, unsigned int block_size, int64_t
    out = output_file_new_normal();
    out = output_file_new_normal();
  }
  }
  if (!out) {
  if (!out) {
    return NULL;
    return nullptr;
  }
  }


  out->ops->open(out, fd);
  out->ops->open(out, fd);
@@ -634,7 +634,7 @@ struct output_file* output_file_open_fd(int fd, unsigned int block_size, int64_t
  ret = output_file_init(out, block_size, len, sparse, chunks, crc);
  ret = output_file_init(out, block_size, len, sparse, chunks, crc);
  if (ret < 0) {
  if (ret < 0) {
    free(out);
    free(out);
    return NULL;
    return nullptr;
  }
  }


  return out;
  return out;
@@ -664,7 +664,7 @@ int write_fd_chunk(struct output_file* out, unsigned int len, int fd, int64_t of
#ifndef _WIN32
#ifndef _WIN32
  if (buffer_size > SIZE_MAX) return -E2BIG;
  if (buffer_size > SIZE_MAX) return -E2BIG;
  char* data =
  char* data =
      reinterpret_cast<char*>(mmap64(NULL, buffer_size, PROT_READ, MAP_SHARED, fd, aligned_offset));
      reinterpret_cast<char*>(mmap64(nullptr, buffer_size, PROT_READ, MAP_SHARED, fd, aligned_offset));
  if (data == MAP_FAILED) {
  if (data == MAP_FAILED) {
    return -errno;
    return -errno;
  }
  }
+1 −1
Original line number Original line Diff line number Diff line
@@ -66,7 +66,7 @@ int main(int argc, char* argv[]) {
    exit(-1);
    exit(-1);
  }
  }


  files = sparse_file_resparse(s, max_size, NULL, 0);
  files = sparse_file_resparse(s, max_size, nullptr, 0);
  if (files < 0) {
  if (files < 0) {
    fprintf(stderr, "Failed to resparse\n");
    fprintf(stderr, "Failed to resparse\n");
    exit(-1);
    exit(-1);
+7 −7
Original line number Original line Diff line number Diff line
@@ -30,13 +30,13 @@
struct sparse_file* sparse_file_new(unsigned int block_size, int64_t len) {
struct sparse_file* sparse_file_new(unsigned int block_size, int64_t len) {
  struct sparse_file* s = reinterpret_cast<sparse_file*>(calloc(sizeof(struct sparse_file), 1));
  struct sparse_file* s = reinterpret_cast<sparse_file*>(calloc(sizeof(struct sparse_file), 1));
  if (!s) {
  if (!s) {
    return NULL;
    return nullptr;
  }
  }


  s->backed_block_list = backed_block_list_new(block_size);
  s->backed_block_list = backed_block_list_new(block_size);
  if (!s->backed_block_list) {
  if (!s->backed_block_list) {
    free(s);
    free(s);
    return NULL;
    return nullptr;
  }
  }


  s->block_size = block_size;
  s->block_size = block_size;
@@ -252,7 +252,7 @@ static struct backed_block* move_chunks_up_to_len(struct sparse_file* from, stru
                                                  unsigned int len) {
                                                  unsigned int len) {
  int64_t count = 0;
  int64_t count = 0;
  struct output_file* out_counter;
  struct output_file* out_counter;
  struct backed_block* last_bb = NULL;
  struct backed_block* last_bb = nullptr;
  struct backed_block* bb;
  struct backed_block* bb;
  struct backed_block* start;
  struct backed_block* start;
  unsigned int last_block = 0;
  unsigned int last_block = 0;
@@ -270,7 +270,7 @@ static struct backed_block* move_chunks_up_to_len(struct sparse_file* from, stru
  out_counter = output_file_open_callback(out_counter_write, &count, to->block_size, to->len, false,
  out_counter = output_file_open_callback(out_counter_write, &count, to->block_size, to->len, false,
                                          true, 0, false);
                                          true, 0, false);
  if (!out_counter) {
  if (!out_counter) {
    return NULL;
    return nullptr;
  }
  }


  for (bb = start; bb; bb = backed_block_iter_next(bb)) {
  for (bb = start; bb; bb = backed_block_iter_next(bb)) {
@@ -281,7 +281,7 @@ static struct backed_block* move_chunks_up_to_len(struct sparse_file* from, stru
    /* will call out_counter_write to update count */
    /* will call out_counter_write to update count */
    ret = sparse_file_write_block(out_counter, bb);
    ret = sparse_file_write_block(out_counter, bb);
    if (ret) {
    if (ret) {
      bb = NULL;
      bb = nullptr;
      goto out;
      goto out;
    }
    }
    if (file_len + count > len) {
    if (file_len + count > len) {
@@ -330,13 +330,13 @@ int sparse_file_resparse(struct sparse_file* in_s, unsigned int max_len, struct
    if (c < out_s_count) {
    if (c < out_s_count) {
      out_s[c] = s;
      out_s[c] = s;
    } else {
    } else {
      backed_block_list_move(s->backed_block_list, tmp->backed_block_list, NULL, NULL);
      backed_block_list_move(s->backed_block_list, tmp->backed_block_list, nullptr, nullptr);
      sparse_file_destroy(s);
      sparse_file_destroy(s);
    }
    }
    c++;
    c++;
  } while (bb);
  } while (bb);


  backed_block_list_move(tmp->backed_block_list, in_s->backed_block_list, NULL, NULL);
  backed_block_list_move(tmp->backed_block_list, in_s->backed_block_list, nullptr, nullptr);


  sparse_file_destroy(tmp);
  sparse_file_destroy(tmp);


+14 −14
Original line number Original line Diff line number Diff line
@@ -276,7 +276,7 @@ static int process_crc32_chunk(SparseFileSource* source, unsigned int chunk_size
    return ret;
    return ret;
  }
  }


  if (crc32 != NULL && file_crc32 != *crc32) {
  if (crc32 != nullptr && file_crc32 != *crc32) {
    return -EINVAL;
    return -EINVAL;
  }
  }


@@ -339,7 +339,7 @@ static int sparse_file_read_sparse(struct sparse_file* s, SparseFileSource* sour
  sparse_header_t sparse_header;
  sparse_header_t sparse_header;
  chunk_header_t chunk_header;
  chunk_header_t chunk_header;
  uint32_t crc32 = 0;
  uint32_t crc32 = 0;
  uint32_t* crc_ptr = 0;
  uint32_t* crc_ptr = nullptr;
  unsigned int cur_block = 0;
  unsigned int cur_block = 0;


  if (!copybuf) {
  if (!copybuf) {
@@ -489,39 +489,39 @@ static struct sparse_file* sparse_file_import_source(SparseFileSource* source, b
  ret = source->ReadValue(&sparse_header, sizeof(sparse_header));
  ret = source->ReadValue(&sparse_header, sizeof(sparse_header));
  if (ret < 0) {
  if (ret < 0) {
    verbose_error(verbose, ret, "header");
    verbose_error(verbose, ret, "header");
    return NULL;
    return nullptr;
  }
  }


  if (sparse_header.magic != SPARSE_HEADER_MAGIC) {
  if (sparse_header.magic != SPARSE_HEADER_MAGIC) {
    verbose_error(verbose, -EINVAL, "header magic");
    verbose_error(verbose, -EINVAL, "header magic");
    return NULL;
    return nullptr;
  }
  }


  if (sparse_header.major_version != SPARSE_HEADER_MAJOR_VER) {
  if (sparse_header.major_version != SPARSE_HEADER_MAJOR_VER) {
    verbose_error(verbose, -EINVAL, "header major version");
    verbose_error(verbose, -EINVAL, "header major version");
    return NULL;
    return nullptr;
  }
  }


  if (sparse_header.file_hdr_sz < SPARSE_HEADER_LEN) {
  if (sparse_header.file_hdr_sz < SPARSE_HEADER_LEN) {
    return NULL;
    return nullptr;
  }
  }


  if (sparse_header.chunk_hdr_sz < sizeof(chunk_header_t)) {
  if (sparse_header.chunk_hdr_sz < sizeof(chunk_header_t)) {
    return NULL;
    return nullptr;
  }
  }


  len = (int64_t)sparse_header.total_blks * sparse_header.blk_sz;
  len = (int64_t)sparse_header.total_blks * sparse_header.blk_sz;
  s = sparse_file_new(sparse_header.blk_sz, len);
  s = sparse_file_new(sparse_header.blk_sz, len);
  if (!s) {
  if (!s) {
    verbose_error(verbose, -EINVAL, NULL);
    verbose_error(verbose, -EINVAL, nullptr);
    return NULL;
    return nullptr;
  }
  }


  ret = source->SetOffset(0);
  ret = source->SetOffset(0);
  if (ret < 0) {
  if (ret < 0) {
    verbose_error(verbose, ret, "seeking");
    verbose_error(verbose, ret, "seeking");
    sparse_file_destroy(s);
    sparse_file_destroy(s);
    return NULL;
    return nullptr;
  }
  }


  s->verbose = verbose;
  s->verbose = verbose;
@@ -529,7 +529,7 @@ static struct sparse_file* sparse_file_import_source(SparseFileSource* source, b
  ret = sparse_file_read_sparse(s, source, crc);
  ret = sparse_file_read_sparse(s, source, crc);
  if (ret < 0) {
  if (ret < 0) {
    sparse_file_destroy(s);
    sparse_file_destroy(s);
    return NULL;
    return nullptr;
  }
  }


  return s;
  return s;
@@ -557,20 +557,20 @@ struct sparse_file* sparse_file_import_auto(int fd, bool crc, bool verbose) {


  len = lseek64(fd, 0, SEEK_END);
  len = lseek64(fd, 0, SEEK_END);
  if (len < 0) {
  if (len < 0) {
    return NULL;
    return nullptr;
  }
  }


  lseek64(fd, 0, SEEK_SET);
  lseek64(fd, 0, SEEK_SET);


  s = sparse_file_new(4096, len);
  s = sparse_file_new(4096, len);
  if (!s) {
  if (!s) {
    return NULL;
    return nullptr;
  }
  }


  ret = sparse_file_read_normal(s, fd);
  ret = sparse_file_read_normal(s, fd);
  if (ret < 0) {
  if (ret < 0) {
    sparse_file_destroy(s);
    sparse_file_destroy(s);
    return NULL;
    return nullptr;
  }
  }


  return s;
  return s;