summaryrefslogtreecommitdiff
path: root/examples/libc/memory.c
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2021-03-31 14:15:21 +0800
committerGitHub <[email protected]>2021-03-31 14:15:21 +0800
commit259144b2e658d6bdc543afb6b2e88f5461a070b4 (patch)
tree7e4e1a241a70330b4f6a4e78d6549c9e68d4873d /examples/libc/memory.c
parent28ec21671cfd8992b3ad2d6ea48989968ad23e7c (diff)
parenta15040d3a9175b13486d756eafe0dd03645368da (diff)
Merge branch 'master' into master
Diffstat (limited to 'examples/libc/memory.c')
-rw-r--r--examples/libc/memory.c64
1 files changed, 34 insertions, 30 deletions
diff --git a/examples/libc/memory.c b/examples/libc/memory.c
index ee524fa43d..063d90cfdc 100644
--- a/examples/libc/memory.c
+++ b/examples/libc/memory.c
@@ -1,9 +1,13 @@
/*
- * memory.c
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
- * Created on: 2010-11-17
- * Author: bernard
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2010-11-17 Bernard first version
*/
+
#include <stdio.h>
#include <stdlib.h>
#include <finsh.h>
@@ -12,45 +16,45 @@
static int errors = 0;
static void merror(const char *msg)
{
- ++errors;
- printf("Error: %s\n", msg);
+ ++errors;
+ printf("Error: %s\n", msg);
}
int libc_mem(void)
{
- void *p;
- int save;
+ void *p;
+ int save;
- errno = 0;
+ errno = 0;
- p = malloc(-1);
- save = errno;
+ p = malloc(-1);
+ save = errno;
- if (p != NULL)
- merror("malloc (-1) succeeded.");
+ if (p != NULL)
+ merror("malloc (-1) succeeded.");
- if (p == NULL && save != ENOMEM)
- merror("errno is not set correctly");
+ if (p == NULL && save != ENOMEM)
+ merror("errno is not set correctly");
- p = malloc(10);
- if (p == NULL)
- merror("malloc (10) failed.");
+ p = malloc(10);
+ if (p == NULL)
+ merror("malloc (10) failed.");
- /* realloc (p, 0) == free (p). */
- p = realloc(p, 0);
- if (p != NULL)
- merror("realloc (p, 0) failed.");
+ /* realloc (p, 0) == free (p). */
+ p = realloc(p, 0);
+ if (p != NULL)
+ merror("realloc (p, 0) failed.");
- p = malloc(0);
- if (p == NULL)
- {
- printf("malloc(0) returns NULL\n");
- }
+ p = malloc(0);
+ if (p == NULL)
+ {
+ printf("malloc(0) returns NULL\n");
+ }
- p = realloc(p, 0);
- if (p != NULL)
- merror("realloc (p, 0) failed.");
+ p = realloc(p, 0);
+ if (p != NULL)
+ merror("realloc (p, 0) failed.");
- return errors != 0;
+ return errors != 0;
}
FINSH_FUNCTION_EXPORT(libc_mem, memory test for libc);