Skip to content

Commit

Permalink
update: replace with nullptr; replace with loge
Browse files Browse the repository at this point in the history
  • Loading branch information
park671 committed Nov 24, 2024
1 parent 0c85e76 commit f2d4bee
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion logger/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
char *get_current_time_str() {
static char buffer[30];
struct timeval tv;
gettimeofday(&tv, NULL);
gettimeofday(&tv, nullptr);

struct tm *local = localtime(&tv.tv_sec);

Expand Down
4 changes: 2 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

#define MAIN_TAG "main"

static const char *outputFileName = NULL;
static const char *sourceFileName = NULL;
static const char *outputFileName = nullptr;
static const char *sourceFileName = nullptr;
static Arch targetArch = ARCH_ARM64;
static Platform targetPlatform = PLATFORM_LINUX;
static int optimizationLevel = -1;
Expand Down
11 changes: 5 additions & 6 deletions wrapper/elf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "elf.h"
#include "file.h"
#include "mspace.h"
#include <string.h>
#include "assembler.h"
#include "logger.h"

Expand All @@ -26,9 +25,9 @@ Elf64_Ehdr *createElfHeader(uint16_t type,
Elf64_Ehdr *ehdr = (Elf64_Ehdr *) malloc(sizeof(Elf64_Ehdr));

// 检查分配是否成功
if (ehdr == NULL) {
if (ehdr == nullptr) {
printf("Memory allocation failed\n");
return NULL;
return nullptr;
}

// 填充 e_ident 魔术字节和标识信息
Expand Down Expand Up @@ -107,9 +106,9 @@ Elf64_Shdr *createSectionHeader(uint32_t name,
Elf64_Shdr *shdr = (Elf64_Shdr *) malloc(sizeof(Elf64_Shdr));

// 检查分配是否成功
if (shdr == NULL) {
fprintf(stderr, "Error: memory allocation failed\n");
return NULL;
if (shdr == nullptr) {
loge(ELF_TAG, "Error: memory allocation failed\n");
return nullptr;
}

// 填充节头字段
Expand Down
16 changes: 8 additions & 8 deletions wrapper/macho.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ mach_header_64 *createMachHeader64(uint32_t cputype,
mach_header_64 *header = (mach_header_64 *) malloc(sizeof(mach_header_64));

// 检查分配是否成功
if (header == NULL) {
if (header == nullptr) {
printf("Memory allocation failed\n");
return NULL;
return nullptr;
}

// 填充 Mach-O 头部字段
Expand Down Expand Up @@ -52,9 +52,9 @@ segment_command_64 *createSegmentCommand64(const char *segname,
segment_command_64 *segment = (segment_command_64 *) malloc(sizeof(segment_command_64));

// 检查分配是否成功
if (segment == NULL) {
if (segment == nullptr) {
printf("Memory allocation failed\n");
return NULL;
return nullptr;
}

// 填充段命令字段
Expand All @@ -81,9 +81,9 @@ symtab_command *createSymtabCommand(uint32_t symoff,
symtab_command *symtab = (symtab_command *) malloc(sizeof(symtab_command));

// 检查分配是否成功
if (symtab == NULL) {
if (symtab == nullptr) {
printf("Memory allocation failed\n");
return NULL;
return nullptr;
}

// 填充符号表命令字段
Expand All @@ -110,9 +110,9 @@ section_64 *createSection64(const char *sectname,
section_64 *section = (section_64 *) malloc(sizeof(section_64));

// 检查分配是否成功
if (section == NULL) {
if (section == nullptr) {
printf("Memory allocation failed\n");
return NULL;
return nullptr;
}

// 填充区块字段
Expand Down
16 changes: 8 additions & 8 deletions wrapper/pe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ OptionalHeader *createOptionalHeader(uint16_t numberOfSections,
uint32_t fileAlignment) {
// 分配可选头内存
OptionalHeader *optionalHeader = (OptionalHeader *) malloc(sizeof(OptionalHeader));
if (optionalHeader == NULL) {
if (optionalHeader == nullptr) {
loge(PE_TAG, "Memory allocation for Optional header failed\n");
return NULL;
return nullptr;
}

// 填充可选头
Expand Down Expand Up @@ -153,9 +153,9 @@ SectionHeader *createSectionHeader(const char *name,
SectionHeader *sectionheader = (SectionHeader *) malloc(sizeof(SectionHeader));

// 检查分配是否成功
if (sectionheader == NULL) {
fprintf(stderr, "Error: memory allocation failed\n");
return NULL;
if (sectionheader == nullptr) {
loge(PE_TAG, "Error: memory allocation failed\n");
return nullptr;
}

// 填充节头字段
Expand Down Expand Up @@ -186,9 +186,9 @@ ProgramSegment *createProgramSegment(uint32_t type,
ProgramSegment *segment = (ProgramSegment *) malloc(sizeof(ProgramSegment));

// 检查分配是否成功
if (segment == NULL) {
fprintf(stderr, "Error: memory allocation failed\n");
return NULL;
if (segment == nullptr) {
loge(PE_TAG, "Error: memory allocation failed\n");
return nullptr;
}

// 填充段信息字段
Expand Down

0 comments on commit f2d4bee

Please sign in to comment.