Skip to content

Commit 48e3cde

Browse files
kongyGerrit Code Review
authored andcommitted
Merge "[libsparse] Modernize codebase by replacing NULL with nullptr"
2 parents 32acd31 + 17ba95e commit 48e3cde

File tree

5 files changed

+47
-47
lines changed

5 files changed

+47
-47
lines changed

libsparse/backed_block.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void backed_block_list_move(struct backed_block_list* from, struct backed_block_
133133
struct backed_block* start, struct backed_block* end) {
134134
struct backed_block* bb;
135135

136-
if (start == NULL) {
136+
if (start == nullptr) {
137137
start = from->data_blocks;
138138
}
139139

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

145-
if (start == NULL || end == NULL) {
145+
if (start == nullptr || end == nullptr) {
146146
return;
147147
}
148148

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

162162
if (!to->data_blocks) {
163163
to->data_blocks = start;
164-
end->next = NULL;
164+
end->next = nullptr;
165165
} else {
166166
for (bb = to->data_blocks; bb; bb = bb->next) {
167167
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
230230
static int queue_bb(struct backed_block_list* bbl, struct backed_block* new_bb) {
231231
struct backed_block* bb;
232232

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

256-
if (bb->next == NULL) {
256+
if (bb->next == nullptr) {
257257
bb->next = new_bb;
258258
} else {
259259
new_bb->next = bb->next;
@@ -273,15 +273,15 @@ static int queue_bb(struct backed_block_list* bbl, struct backed_block* new_bb)
273273
int backed_block_add_fill(struct backed_block_list* bbl, unsigned int fill_val, unsigned int len,
274274
unsigned int block) {
275275
struct backed_block* bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
276-
if (bb == NULL) {
276+
if (bb == nullptr) {
277277
return -ENOMEM;
278278
}
279279

280280
bb->block = block;
281281
bb->len = len;
282282
bb->type = BACKED_BLOCK_FILL;
283283
bb->fill.val = fill_val;
284-
bb->next = NULL;
284+
bb->next = nullptr;
285285

286286
return queue_bb(bbl, bb);
287287
}
@@ -290,15 +290,15 @@ int backed_block_add_fill(struct backed_block_list* bbl, unsigned int fill_val,
290290
int backed_block_add_data(struct backed_block_list* bbl, void* data, unsigned int len,
291291
unsigned int block) {
292292
struct backed_block* bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
293-
if (bb == NULL) {
293+
if (bb == nullptr) {
294294
return -ENOMEM;
295295
}
296296

297297
bb->block = block;
298298
bb->len = len;
299299
bb->type = BACKED_BLOCK_DATA;
300300
bb->data.data = data;
301-
bb->next = NULL;
301+
bb->next = nullptr;
302302

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

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

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

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

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

352352
new_bb = reinterpret_cast<backed_block*>(malloc(sizeof(struct backed_block)));
353-
if (new_bb == NULL) {
353+
if (new_bb == nullptr) {
354354
return -ENOMEM;
355355
}
356356

libsparse/output_file.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static int gz_file_write(struct output_file* out, void* data, size_t len) {
233233
while (len > 0) {
234234
ret = gzwrite(outgz->gz_fd, data, min(len, (unsigned int)INT_MAX));
235235
if (ret == 0) {
236-
error("gzwrite %s", gzerror(outgz->gz_fd, NULL));
236+
error("gzwrite %s", gzerror(outgz->gz_fd, nullptr));
237237
return -1;
238238
}
239239
len -= ret;
@@ -269,7 +269,7 @@ static int callback_file_skip(struct output_file* out, int64_t off) {
269269

270270
while (off > 0) {
271271
to_write = min(off, (int64_t)INT_MAX);
272-
ret = outc->write(outc->priv, NULL, to_write);
272+
ret = outc->write(outc->priv, nullptr, to_write);
273273
if (ret < 0) {
274274
return ret;
275275
}
@@ -568,7 +568,7 @@ static struct output_file* output_file_new_gz(void) {
568568
reinterpret_cast<struct output_file_gz*>(calloc(1, sizeof(struct output_file_gz)));
569569
if (!outgz) {
570570
error_errno("malloc struct outgz");
571-
return NULL;
571+
return nullptr;
572572
}
573573

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

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

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

615615
return &outc->out;
@@ -626,15 +626,15 @@ struct output_file* output_file_open_fd(int fd, unsigned int block_size, int64_t
626626
out = output_file_new_normal();
627627
}
628628
if (!out) {
629-
return NULL;
629+
return nullptr;
630630
}
631631

632632
out->ops->open(out, fd);
633633

634634
ret = output_file_init(out, block_size, len, sparse, chunks, crc);
635635
if (ret < 0) {
636636
free(out);
637-
return NULL;
637+
return nullptr;
638638
}
639639

640640
return out;
@@ -664,7 +664,7 @@ int write_fd_chunk(struct output_file* out, unsigned int len, int fd, int64_t of
664664
#ifndef _WIN32
665665
if (buffer_size > SIZE_MAX) return -E2BIG;
666666
char* data =
667-
reinterpret_cast<char*>(mmap64(NULL, buffer_size, PROT_READ, MAP_SHARED, fd, aligned_offset));
667+
reinterpret_cast<char*>(mmap64(nullptr, buffer_size, PROT_READ, MAP_SHARED, fd, aligned_offset));
668668
if (data == MAP_FAILED) {
669669
return -errno;
670670
}

libsparse/simg2simg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int main(int argc, char* argv[]) {
6666
exit(-1);
6767
}
6868

69-
files = sparse_file_resparse(s, max_size, NULL, 0);
69+
files = sparse_file_resparse(s, max_size, nullptr, 0);
7070
if (files < 0) {
7171
fprintf(stderr, "Failed to resparse\n");
7272
exit(-1);

libsparse/sparse.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
struct sparse_file* sparse_file_new(unsigned int block_size, int64_t len) {
3131
struct sparse_file* s = reinterpret_cast<sparse_file*>(calloc(sizeof(struct sparse_file), 1));
3232
if (!s) {
33-
return NULL;
33+
return nullptr;
3434
}
3535

3636
s->backed_block_list = backed_block_list_new(block_size);
3737
if (!s->backed_block_list) {
3838
free(s);
39-
return NULL;
39+
return nullptr;
4040
}
4141

4242
s->block_size = block_size;
@@ -252,7 +252,7 @@ static struct backed_block* move_chunks_up_to_len(struct sparse_file* from, stru
252252
unsigned int len) {
253253
int64_t count = 0;
254254
struct output_file* out_counter;
255-
struct backed_block* last_bb = NULL;
255+
struct backed_block* last_bb = nullptr;
256256
struct backed_block* bb;
257257
struct backed_block* start;
258258
unsigned int last_block = 0;
@@ -270,7 +270,7 @@ static struct backed_block* move_chunks_up_to_len(struct sparse_file* from, stru
270270
out_counter = output_file_open_callback(out_counter_write, &count, to->block_size, to->len, false,
271271
true, 0, false);
272272
if (!out_counter) {
273-
return NULL;
273+
return nullptr;
274274
}
275275

276276
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
281281
/* will call out_counter_write to update count */
282282
ret = sparse_file_write_block(out_counter, bb);
283283
if (ret) {
284-
bb = NULL;
284+
bb = nullptr;
285285
goto out;
286286
}
287287
if (file_len + count > len) {
@@ -330,13 +330,13 @@ int sparse_file_resparse(struct sparse_file* in_s, unsigned int max_len, struct
330330
if (c < out_s_count) {
331331
out_s[c] = s;
332332
} else {
333-
backed_block_list_move(s->backed_block_list, tmp->backed_block_list, NULL, NULL);
333+
backed_block_list_move(s->backed_block_list, tmp->backed_block_list, nullptr, nullptr);
334334
sparse_file_destroy(s);
335335
}
336336
c++;
337337
} while (bb);
338338

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

341341
sparse_file_destroy(tmp);
342342

libsparse/sparse_read.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static int process_crc32_chunk(SparseFileSource* source, unsigned int chunk_size
276276
return ret;
277277
}
278278

279-
if (crc32 != NULL && file_crc32 != *crc32) {
279+
if (crc32 != nullptr && file_crc32 != *crc32) {
280280
return -EINVAL;
281281
}
282282

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

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

495495
if (sparse_header.magic != SPARSE_HEADER_MAGIC) {
496496
verbose_error(verbose, -EINVAL, "header magic");
497-
return NULL;
497+
return nullptr;
498498
}
499499

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

505505
if (sparse_header.file_hdr_sz < SPARSE_HEADER_LEN) {
506-
return NULL;
506+
return nullptr;
507507
}
508508

509509
if (sparse_header.chunk_hdr_sz < sizeof(chunk_header_t)) {
510-
return NULL;
510+
return nullptr;
511511
}
512512

513513
len = (int64_t)sparse_header.total_blks * sparse_header.blk_sz;
514514
s = sparse_file_new(sparse_header.blk_sz, len);
515515
if (!s) {
516-
verbose_error(verbose, -EINVAL, NULL);
517-
return NULL;
516+
verbose_error(verbose, -EINVAL, nullptr);
517+
return nullptr;
518518
}
519519

520520
ret = source->SetOffset(0);
521521
if (ret < 0) {
522522
verbose_error(verbose, ret, "seeking");
523523
sparse_file_destroy(s);
524-
return NULL;
524+
return nullptr;
525525
}
526526

527527
s->verbose = verbose;
528528

529529
ret = sparse_file_read_sparse(s, source, crc);
530530
if (ret < 0) {
531531
sparse_file_destroy(s);
532-
return NULL;
532+
return nullptr;
533533
}
534534

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

558558
len = lseek64(fd, 0, SEEK_END);
559559
if (len < 0) {
560-
return NULL;
560+
return nullptr;
561561
}
562562

563563
lseek64(fd, 0, SEEK_SET);
564564

565565
s = sparse_file_new(4096, len);
566566
if (!s) {
567-
return NULL;
567+
return nullptr;
568568
}
569569

570570
ret = sparse_file_read_normal(s, fd);
571571
if (ret < 0) {
572572
sparse_file_destroy(s);
573-
return NULL;
573+
return nullptr;
574574
}
575575

576576
return s;

0 commit comments

Comments
 (0)