|
|
@@ -15,6 +15,9 @@ test_sqrt(int x, int y);
|
|
|
int
|
|
|
test_hello(const char *name, char *buf, size_t buflen);
|
|
|
|
|
|
+int
|
|
|
+test_hello2(const char *name, char *buf, size_t buflen);
|
|
|
+
|
|
|
int
|
|
|
main(int argc, char **argv)
|
|
|
{
|
|
|
@@ -33,12 +36,35 @@ main(int argc, char **argv)
|
|
|
|
|
|
res = test_hello(name, NULL, 0);
|
|
|
printf("test_hello(\"%s\", %p, %zu) = %d\n", name, NULL, (size_t)0, res);
|
|
|
+ if (res == -1) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
buflen = res + 1;
|
|
|
buf = malloc(buflen);
|
|
|
printf("malloc(%zu) = %p\n", buflen, buf);
|
|
|
res = test_hello(__func__, buf, buflen);
|
|
|
+ if (res == -1) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
printf("test_hello(\"%s\", %p, %zu) = %d\n", name, buf, buflen, res);
|
|
|
printf("Message from test_hello: %s", buf);
|
|
|
+ free(buf);
|
|
|
+
|
|
|
+ res = test_hello2(name, NULL, 0);
|
|
|
+ printf("test_hello2(\"%s\", %p, %zu) = %d\n", name, NULL, (size_t)0, res);
|
|
|
+ if (res == -1) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ buflen = res + 1;
|
|
|
+ buf = malloc(buflen);
|
|
|
+ printf("malloc(%zu) = %p\n", buflen, buf);
|
|
|
+ res = test_hello2(__func__, buf, buflen);
|
|
|
+ if (res == -1) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ printf("test_hello2(\"%s\", %p, %zu) = %d\n", name, buf, buflen, res);
|
|
|
+ printf("Message from test_hello2: %s", buf);
|
|
|
+ free(buf);
|
|
|
|
|
|
return 0;
|
|
|
}
|