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

Commit 95221b51 authored by Iliyan Malchev's avatar Iliyan Malchev Committed by Android (Google) Code Review
Browse files

Merge "libs/utils: replace malloc() + memset() to zero with calloc()"

parents 18ce4566 7e1d3956
Loading
Loading
Loading
Loading
+1 −4
Original line number Original line Diff line number Diff line
@@ -546,7 +546,7 @@ int write_tarfile(const String8& packageName, const String8& domain,


    // read/write up to this much at a time.
    // read/write up to this much at a time.
    const size_t BUFSIZE = 32 * 1024;
    const size_t BUFSIZE = 32 * 1024;
    char* buf = new char[BUFSIZE];
    char* buf = (char *)calloc(1,BUFSIZE);
    char* paxHeader = buf + 512;    // use a different chunk of it as separate scratch
    char* paxHeader = buf + 512;    // use a different chunk of it as separate scratch
    char* paxData = buf + 1024;
    char* paxData = buf + 1024;


@@ -556,9 +556,6 @@ int write_tarfile(const String8& packageName, const String8& domain,
        goto cleanup;
        goto cleanup;
    }
    }


    // Good to go -- first construct the standard tar header at the start of the buffer
    memset(buf, 0, BUFSIZE);

    // Magic fields for the ustar file format
    // Magic fields for the ustar file format
    strcat(buf + 257, "ustar");
    strcat(buf + 257, "ustar");
    strcat(buf + 263, "00");
    strcat(buf + 263, "00");
+3 −6
Original line number Original line Diff line number Diff line
@@ -379,8 +379,7 @@ status_t ResStringPool::setTo(const void* data, size_t size, bool copyData)
        size_t charSize;
        size_t charSize;
        if (mHeader->flags&ResStringPool_header::UTF8_FLAG) {
        if (mHeader->flags&ResStringPool_header::UTF8_FLAG) {
            charSize = sizeof(uint8_t);
            charSize = sizeof(uint8_t);
            mCache = (char16_t**)malloc(sizeof(char16_t**)*mHeader->stringCount);
            mCache = (char16_t**)calloc(mHeader->stringCount, sizeof(char16_t**));
            memset(mCache, 0, sizeof(char16_t**)*mHeader->stringCount);
        } else {
        } else {
            charSize = sizeof(char16_t);
            charSize = sizeof(char16_t);
        }
        }
@@ -3252,16 +3251,14 @@ ssize_t ResTable::getBagLocked(uint32_t resID, const bag_entry** outBag,


    // Bag not found, we need to compute it!
    // Bag not found, we need to compute it!
    if (!grp->bags) {
    if (!grp->bags) {
        grp->bags = (bag_set***)malloc(sizeof(bag_set*)*grp->typeCount);
        grp->bags = (bag_set***)calloc(grp->typeCount, sizeof(bag_set*));
        if (!grp->bags) return NO_MEMORY;
        if (!grp->bags) return NO_MEMORY;
        memset(grp->bags, 0, sizeof(bag_set*)*grp->typeCount);
    }
    }


    bag_set** typeSet = grp->bags[t];
    bag_set** typeSet = grp->bags[t];
    if (!typeSet) {
    if (!typeSet) {
        typeSet = (bag_set**)malloc(sizeof(bag_set*)*NENTRY);
        typeSet = (bag_set**)calloc(NENTRY, sizeof(bag_set*));
        if (!typeSet) return NO_MEMORY;
        if (!typeSet) return NO_MEMORY;
        memset(typeSet, 0, sizeof(bag_set*)*NENTRY);
        grp->bags[t] = typeSet;
        grp->bags[t] = typeSet;
    }
    }