LeetCode: fault list

Posted 三叁

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode: fault list相关的知识,希望对你有一定的参考价值。

1. malloc memory should always use the following form:

int *a = malloc(sizeof(int) * 3);
int **b = malloc(sizeof(int*) * 3);
int i = 0;
for (; i < 3; i++) {
    b[i] = malloc(sizeof(int) * 3);
}
char *c = malloc(sizeof(char) * length);
char **pc = malloc(sizeof(char *) * 4);
for (i = 0; i < 4; i++) {
    pc[i] = malloc(sizeof(char) * 3);
}

2. memset memory to 0 should use the form:

// Using the malloced memory above:
memset(a, 0, sizeof(int) * 3);
memset(b, 0, sizeof(int*) * 3);
for (i = 0; i < 3; i++) {
    memset(b[i], 0, sizeof(int) * 3);
}
memset(c, 0, sizeof(char) * 3);
memset(pc, 0, sizeof(char *) * 4);
for (i = 0; i < 4; i++) {
    memset(pc[i], 0, sizeof(char) * 3);
}

3. malloc(0) might also return address which is non-null. Which is error-prone. Consider use the following malloc. (..my implementation, any suggestion?)

#define SMALLOC(x)       \
({                                   void *addr;                       if ((x) == 0)                   addr = 0;                       else addr = malloc(x);     (addr);                           })

 

以上是关于LeetCode: fault list的主要内容,如果未能解决你的问题,请参考以下文章

VMWare vCenter Converter converter.fault.ManagedDiskOpenFault错误

leetcode_1292. Maximum Side Length of a Square with Sum Less than or Equal to Threshold_[二维前缀和](代码片段

TP5报如下的错误 Indirect modification of overloaded element of thinkpaginatorCollection has no effect(代码片段

Segmentation Fault shell 代码测试 kali 2018

鸿蒙轻内核M核的故障管家:Fault异常处理

Leetcode.1024 视频拼接