summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--minzip/SysUtil.c23
-rw-r--r--updater/updater.cpp13
2 files changed, 18 insertions, 18 deletions
diff --git a/minzip/SysUtil.c b/minzip/SysUtil.c
index e7dd17b51..de47edfd9 100644
--- a/minzip/SysUtil.c
+++ b/minzip/SysUtil.c
@@ -8,6 +8,7 @@
#include <fcntl.h>
#include <limits.h>
#include <stdbool.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -118,13 +119,13 @@ static int sysMapBlockFile(FILE* mapf, MemMapping* pMap)
break;
}
size_t length = (end - start) * blksize;
- if (end <= start || (end - start) > SIZE_MAX / blksize || length > remaining_size) {
- LOGE("unexpected range in block map: %zu %zu\n", start, end);
- success = false;
- break;
+ if (end <= start || ((end - start) > SIZE_MAX / blksize) || length > remaining_size) {
+ LOGE("unexpected range in block map: %zu %zu\n", start, end);
+ success = false;
+ break;
}
- void* addr = mmap64(next, length, PROT_READ, MAP_PRIVATE | MAP_FIXED, fd, ((off64_t)start)*blksize);
+ void* addr = mmap64(next, length, PROT_READ, MAP_PRIVATE | MAP_FIXED, fd, ((off64_t)(start*blksize)));
if (addr == MAP_FAILED) {
LOGE("failed to map block %d: %s\n", i, strerror(errno));
success = false;
@@ -137,14 +138,14 @@ static int sysMapBlockFile(FILE* mapf, MemMapping* pMap)
remaining_size -= length;
}
if (success && remaining_size != 0) {
- LOGE("ranges in block map are invalid: remaining_size = %zu\n", remaining_size);
- success = false;
+ LOGE("ranges in block map are invalid: remaining_size = %zu\n", remaining_size);
+ success = false;
}
if (!success) {
- close(fd);
- munmap(reserve, blocks * blksize);
- free(pMap->ranges);
- return -1;
+ close(fd);
+ munmap(reserve, blocks * blksize);
+ free(pMap->ranges);
+ return -1;
}
close(fd);
diff --git a/updater/updater.cpp b/updater/updater.cpp
index efb4a8cec..0d58f6486 100644
--- a/updater/updater.cpp
+++ b/updater/updater.cpp
@@ -19,6 +19,8 @@
#include <stdlib.h>
#include <string.h>
+#include <string>
+
#include "edify/expr.h"
#include "updater.h"
#include "install.h"
@@ -91,12 +93,11 @@ int main(int argc, char** argv) {
return 4;
}
- char* script = reinterpret_cast<char*>(malloc(script_entry->uncompLen+1));
- if (!mzReadZipEntry(&za, script_entry, script, script_entry->uncompLen)) {
+ std::string script(script_entry->uncompLen, '\0');
+ if (!mzReadZipEntry(&za, script_entry, &script[0], script_entry->uncompLen)) {
printf("failed to read script from package\n");
return 5;
}
- script[script_entry->uncompLen] = '\0';
// Configure edify's functions.
@@ -110,7 +111,7 @@ int main(int argc, char** argv) {
Expr* root;
int error_count = 0;
- int error = parse_string(script, &root, &error_count);
+ int error = parse_string(script.c_str(), &root, &error_count);
if (error != 0 || error_count > 0) {
printf("%d parse errors\n", error_count);
return 6;
@@ -137,7 +138,7 @@ int main(int argc, char** argv) {
State state;
state.cookie = &updater_info;
- state.script = script;
+ state.script = &script[0];
state.errmsg = NULL;
char* result = Evaluate(&state, root);
@@ -165,7 +166,5 @@ int main(int argc, char** argv) {
mzCloseZipArchive(updater_info.package_zip);
}
sysReleaseMap(&map);
- free(script);
-
return 0;
}