Enable -Wextra in tests.
This commit is contained in:
@@ -227,6 +227,7 @@ FLAGS=\
|
||||
-fno-builtin \
|
||||
-fno-stack-protector \
|
||||
-Wall \
|
||||
-Wextra \
|
||||
-Werror \
|
||||
-pedantic \
|
||||
-g \
|
||||
|
||||
+1
-1
@@ -301,7 +301,7 @@ size_t num_test_cases = sizeof(test_cases) / sizeof(struct test_case);
|
||||
int main(void) {
|
||||
int retval = EXIT_SUCCESS;
|
||||
|
||||
for(int i = 0; i < num_test_cases; ++i) {
|
||||
for(size_t i = 0; i < num_test_cases; ++i) {
|
||||
struct test_case tc = test_cases[i];
|
||||
CHECK_TEST(tc, isalnum, retval);
|
||||
CHECK_TEST(tc, isalpha, retval);
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include "test_helpers.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
assert(argc > 0);
|
||||
|
||||
puts(argv[0]);
|
||||
puts(program_invocation_name);
|
||||
puts(program_invocation_short_name);
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ int check_mtime(char *path, int expected_sec, int expected_nsec, int err_gap) {
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int main(void) {
|
||||
char temp[] = "/tmp/stattest-XXXXXX";
|
||||
const char file[] = "/mkfifo_fifo";
|
||||
int len = sizeof(temp) + sizeof(int);
|
||||
|
||||
+3
-3
@@ -2,9 +2,9 @@
|
||||
#include <grp.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
printf("getgrent\n");
|
||||
int main(void) {
|
||||
puts("getgrent\n");
|
||||
|
||||
for (struct group* grp = getgrent(); grp != NULL; grp = getgrent())
|
||||
printf(" %s = %d\n", grp->gr_name, grp->gr_gid);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -111,7 +111,7 @@ int safe_strcmp(char *s1, char *s2) {
|
||||
int main(void) {
|
||||
int retval = EXIT_SUCCESS;
|
||||
|
||||
for(int i = 0; i < num_test_cases; ++i) {
|
||||
for(size_t i = 0; i < num_test_cases; ++i) {
|
||||
struct test_case tc = test_cases[i];
|
||||
CHECK_TEST(tc, dirname, retval);
|
||||
CHECK_TEST(tc, basename, retval);
|
||||
|
||||
+34
-31
@@ -1,3 +1,4 @@
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -10,46 +11,48 @@ const char *msg2 = "second";
|
||||
const char *msg3 = "third";
|
||||
|
||||
void cleanup1(void *arg) {
|
||||
printf("Running %s cleanup callback\n", (const char *)arg);
|
||||
printf("Running %s cleanup callback\n", (const char *)arg);
|
||||
}
|
||||
void cleanup2(void *arg) {
|
||||
fprintf(stderr, "Running %s cleanup callback, to stderr\n", (const char *)arg);
|
||||
fprintf(stderr, "Running %s cleanup callback, to stderr\n", (const char *)arg);
|
||||
}
|
||||
void cleanup3(void *arg) {
|
||||
printf("Running final (%s) callback\n", (const char *)arg);
|
||||
printf("Running final (%s) callback\n", (const char *)arg);
|
||||
}
|
||||
|
||||
void *routine(void *arg) {
|
||||
puts("1");
|
||||
pthread_cleanup_push(cleanup1, msg1);
|
||||
puts("2");
|
||||
pthread_cleanup_push(cleanup2, msg2);
|
||||
puts("3");
|
||||
pthread_cleanup_push(cleanup3, msg3);
|
||||
puts("4");
|
||||
pthread_cleanup_pop(true);
|
||||
puts("5");
|
||||
//exit(EXIT_SUCCESS);
|
||||
pthread_exit(NULL);
|
||||
puts("6");
|
||||
pthread_cleanup_pop(true);
|
||||
pthread_cleanup_pop(true);
|
||||
return NULL;
|
||||
assert(arg == NULL);
|
||||
|
||||
puts("1");
|
||||
pthread_cleanup_push(cleanup1, msg1);
|
||||
puts("2");
|
||||
pthread_cleanup_push(cleanup2, msg2);
|
||||
puts("3");
|
||||
pthread_cleanup_push(cleanup3, msg3);
|
||||
puts("4");
|
||||
pthread_cleanup_pop(true);
|
||||
puts("5");
|
||||
//exit(EXIT_SUCCESS);
|
||||
pthread_exit(NULL);
|
||||
puts("6");
|
||||
pthread_cleanup_pop(true);
|
||||
pthread_cleanup_pop(true);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int result;
|
||||
int result;
|
||||
|
||||
puts("Main thread started");
|
||||
pthread_t second_thread;
|
||||
if ((result = pthread_create(&second_thread, NULL, routine, NULL)) != 0) {
|
||||
fprintf(stderr, "thread creation failed: %s\n", strerror(result));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if ((result = pthread_join(second_thread, NULL)) != 0) {
|
||||
fprintf(stderr, "failed to join thread: %s\n", strerror(result));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
puts("Main thread about to exit");
|
||||
return EXIT_SUCCESS;
|
||||
puts("Main thread started");
|
||||
pthread_t second_thread;
|
||||
if ((result = pthread_create(&second_thread, NULL, routine, NULL)) != 0) {
|
||||
fprintf(stderr, "thread creation failed: %s\n", strerror(result));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if ((result = pthread_join(second_thread, NULL)) != 0) {
|
||||
fprintf(stderr, "failed to join thread: %s\n", strerror(result));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
puts("Main thread about to exit");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
+37
-36
@@ -8,60 +8,61 @@
|
||||
#include "common.h"
|
||||
|
||||
struct arg2 {
|
||||
int status;
|
||||
pthread_t t1;
|
||||
int status;
|
||||
pthread_t t1;
|
||||
};
|
||||
|
||||
void *routine1(void *arg) {
|
||||
puts("Thread 1 spawned, waiting 1s.");
|
||||
sleep(1);
|
||||
puts("Thread 1 finished.");
|
||||
return strdup("message from thread 1");
|
||||
assert(arg == NULL);
|
||||
puts("Thread 1 spawned, waiting 1s.");
|
||||
sleep(1);
|
||||
puts("Thread 1 finished.");
|
||||
return strdup("message from thread 1");
|
||||
}
|
||||
void *routine2(void *arg_raw) {
|
||||
struct arg2 *arg = arg_raw;
|
||||
struct arg2 *arg = arg_raw;
|
||||
|
||||
puts("Thread 2 spawned, awaiting thread 1.");
|
||||
puts("Thread 2 spawned, awaiting thread 1.");
|
||||
|
||||
void *retval_raw;
|
||||
int status;
|
||||
void *retval_raw;
|
||||
int status;
|
||||
|
||||
if ((status = pthread_join(arg->t1, &retval_raw)) != 0) {
|
||||
arg->status = fail(status, "t1 join from thread 2");
|
||||
return NULL;
|
||||
}
|
||||
char *retval = retval_raw;
|
||||
|
||||
assert(strcmp(retval, "message from thread 1") == 0);
|
||||
|
||||
free(retval);
|
||||
|
||||
if ((status = pthread_join(arg->t1, &retval_raw)) != 0) {
|
||||
arg->status = fail(status, "t1 join from thread 2");
|
||||
return NULL;
|
||||
}
|
||||
char *retval = retval_raw;
|
||||
|
||||
assert(strcmp(retval, "message from thread 1") == 0);
|
||||
|
||||
free(retval);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
pthread_t t1;
|
||||
pthread_t t2;
|
||||
pthread_t t1;
|
||||
pthread_t t2;
|
||||
|
||||
int status;
|
||||
int status;
|
||||
|
||||
puts("Main thread.");
|
||||
puts("Main thread.");
|
||||
|
||||
if ((status = pthread_create(&t1, NULL, routine1, NULL)) != 0) {
|
||||
return fail(status, "t1 create");
|
||||
}
|
||||
if ((status = pthread_create(&t1, NULL, routine1, NULL)) != 0) {
|
||||
return fail(status, "t1 create");
|
||||
}
|
||||
|
||||
puts("Created thread 1.");
|
||||
puts("Created thread 1.");
|
||||
|
||||
struct arg2 arg = { .status = 0, .t1 = t1 };
|
||||
struct arg2 arg = { .status = 0, .t1 = t1 };
|
||||
|
||||
if ((status = pthread_create(&t2, NULL, routine2, &arg)) != 0) {
|
||||
return fail(status, "t2 create");
|
||||
}
|
||||
if ((status = pthread_create(&t2, NULL, routine2, &arg)) != 0) {
|
||||
return fail(status, "t2 create");
|
||||
}
|
||||
|
||||
if ((status = pthread_join(t2, NULL)) != 0) {
|
||||
return fail(status, "t2 join");
|
||||
}
|
||||
if ((status = pthread_join(t2, NULL)) != 0) {
|
||||
return fail(status, "t2 join");
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
+22
-17
@@ -1,3 +1,4 @@
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -8,26 +9,30 @@
|
||||
#include "common.h"
|
||||
|
||||
void *thread_main(void *arg) {
|
||||
puts("Thread main");
|
||||
return NULL;
|
||||
puts("Thread main");
|
||||
|
||||
assert(arg == NULL);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int status;
|
||||
int status;
|
||||
|
||||
puts("Start, sleeping 1 second");
|
||||
sleep(1);
|
||||
pthread_t thread;
|
||||
void *arg = NULL;
|
||||
if ((status = pthread_create(&thread, NULL, thread_main, arg)) != 0) {
|
||||
return fail(status, "create thread");
|
||||
}
|
||||
puts("Started");
|
||||
void *retval;
|
||||
if ((status = pthread_join(thread, &retval)) != 0) {
|
||||
return fail(status, "join thread");
|
||||
}
|
||||
puts("Joined");
|
||||
puts("Start, sleeping 1 second");
|
||||
sleep(1);
|
||||
pthread_t thread;
|
||||
void *arg = NULL;
|
||||
if ((status = pthread_create(&thread, NULL, thread_main, arg)) != 0) {
|
||||
return fail(status, "create thread");
|
||||
}
|
||||
puts("Started");
|
||||
void *retval;
|
||||
if ((status = pthread_join(thread, &retval)) != 0) {
|
||||
return fail(status, "join thread");
|
||||
}
|
||||
assert(retval == NULL);
|
||||
puts("Joined");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
+2
-2
@@ -10,12 +10,12 @@
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
const int SYS_write = 1;
|
||||
#define SYS_write 1
|
||||
|
||||
#endif
|
||||
#ifdef __redox__
|
||||
|
||||
const int SYS_write = 0x21000004;
|
||||
#define SYS_write 0x21000004
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "test_helpers.h"
|
||||
|
||||
void handler(int sig) {
|
||||
UNEXP_IF(signal, sig, != SIGUSR1);
|
||||
puts("Signal handler called!");
|
||||
}
|
||||
|
||||
|
||||
+9
-3
@@ -10,9 +10,15 @@ int main(void) {
|
||||
|
||||
char buf[33] = { 0 };
|
||||
for (int i = 1; i <= 32; ++i) {
|
||||
if (fread(buf, 1, i, fp) < 0) {
|
||||
perror("fread");
|
||||
exit(EXIT_FAILURE);
|
||||
size_t nread = fread(buf, 1, i, fp);
|
||||
if (nread == 0) {
|
||||
if (feof(fp)) {
|
||||
fprintf(stderr, "early EOF\n");
|
||||
return EXIT_FAILURE;
|
||||
} else {
|
||||
perror("fread");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
buf[i] = 0;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
|
||||
@@ -32,7 +33,7 @@ int main(void) {
|
||||
&test_reopen_opens_file,
|
||||
&test_reopen_resets_orientation,
|
||||
};
|
||||
for(int i=0; i<sizeof(tests)/sizeof(int(*)(void)); i++) {
|
||||
for(size_t i = 0; i < sizeof(tests) / sizeof(int(*)(void)); i++) {
|
||||
printf("%d\n", (*tests[i])());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ int main(void) {
|
||||
size_t nonpow2_mul_voidptr_size = 3*sizeof(void *);
|
||||
size_t pow2_mul_voidptr_size = 4*sizeof(void *);
|
||||
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
errno = 0;
|
||||
char * ptr_zerosize_malloc = (char *)malloc(zero_size);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
||||
@@ -12,7 +13,7 @@ int cmpfunc (const void * a_ptr, const void * b_ptr) {
|
||||
}
|
||||
|
||||
int main () {
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
printf("Before: ");
|
||||
for(i = 0; i < ARRAY_SIZE(values); i++) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -73,7 +74,7 @@ int main(void) {
|
||||
"-NaN0.1e5", "-nan-37", "-nAn1.05", "-Nan foo bar baz",
|
||||
|
||||
};
|
||||
for (int i = 0; i < sizeof(inputs) / sizeof(char*); i += 1) {
|
||||
for (size_t i = 0; i < sizeof(inputs) / sizeof(char*); i += 1) {
|
||||
d = strtod(inputs[i], &endptr);
|
||||
printf("d: %f Endptr: \"%s\"\n", d, endptr);
|
||||
}
|
||||
|
||||
+15
-13
@@ -5,6 +5,8 @@
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "../test_helpers.h"
|
||||
|
||||
int reader(int fd) {
|
||||
// Create an epoll file
|
||||
int epollfd = epoll_create1(EPOLL_CLOEXEC);
|
||||
@@ -52,12 +54,12 @@ int reader(int fd) {
|
||||
if (events[n].data.fd == fd) {
|
||||
// Read the current event count
|
||||
int writer_i;
|
||||
int count = read(fd, &writer_i, sizeof(writer_i));
|
||||
if (count < 0) {
|
||||
perror("read");
|
||||
return 1;
|
||||
} else if (count < sizeof(writer_i)) {
|
||||
fprintf(stderr, "read %d instead of %d\n", count, sizeof(writer_i));
|
||||
ssize_t status = read(fd, &writer_i, sizeof(writer_i));
|
||||
ERROR_IF(read, status, == -1);
|
||||
size_t count = (size_t)status;
|
||||
|
||||
if (count < sizeof(writer_i)) {
|
||||
fprintf(stderr, "read %zu instead of %d\n", count, sizeof(writer_i));
|
||||
return 1;
|
||||
}
|
||||
// Make sure the writer's event count matches our own
|
||||
@@ -109,12 +111,12 @@ int writer(int fd) {
|
||||
// If the event is the writer file
|
||||
if (events[n].data.fd == fd) {
|
||||
// Write the current event count
|
||||
int count = write(fd, &i, sizeof(i));
|
||||
if (count < 0) {
|
||||
perror("write");
|
||||
return 1;
|
||||
} else if (count < sizeof(i)) {
|
||||
fprintf(stderr, "wrote %d instead of %d\n", count, sizeof(i));
|
||||
ssize_t status = write(fd, &i, sizeof(i));
|
||||
ERROR_IF(write, status, == -1);
|
||||
size_t count = (size_t)status;
|
||||
|
||||
if (count < sizeof(i)) {
|
||||
fprintf(stderr, "wrote %zu instead of %d\n", count, sizeof(i));
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
@@ -128,7 +130,7 @@ int writer(int fd) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int main(void) {
|
||||
// Create a non-blocking pipe to use for epoll testing
|
||||
int pipefd[2];
|
||||
if (pipe2(pipefd, O_CLOEXEC | O_NONBLOCK) < 0) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
@@ -6,7 +7,7 @@
|
||||
int main(void) {
|
||||
int day = 60 * 60 * 24;
|
||||
time_t inputs[] = { -(day * 33), -day, -1, -500, 0, 1, 1531454950 };
|
||||
for (int i = 0; i < (sizeof(inputs) / sizeof(time_t)); i += 1) {
|
||||
for (size_t i = 0; i < (sizeof(inputs) / sizeof(time_t)); i += 1) {
|
||||
struct tm* t = localtime(&inputs[i]);
|
||||
|
||||
printf(
|
||||
@@ -24,8 +25,7 @@ int main(void) {
|
||||
char *ctime_r_result = ctime_r(&input, ctime_r_buffer);
|
||||
if (ctime_r_result == ctime_r_buffer) {
|
||||
fputs(ctime_r_result, stdout);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printf("Unexpected pointer from ctime_r: %p\n", ctime_r_result);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
_Thread_local int tbss = 0;
|
||||
_Thread_local int tdata = 1;
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
int main(void) {
|
||||
printf("%d == 0\n", tbss);
|
||||
printf("%d == 1\n", tdata);
|
||||
return 0;
|
||||
|
||||
@@ -60,7 +60,7 @@ int runner(int argc, char *argv[]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
int main(void) {
|
||||
RUN("test", "-ao", "arg", "path", "path");
|
||||
RUN("test", "-a", "-o", "arg", "path", "path");
|
||||
RUN("test", "-o", "arg", "-a", "path", "path");
|
||||
|
||||
@@ -55,7 +55,7 @@ void runner(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
int main(void) {
|
||||
RUN("test", "--test0", "-a");
|
||||
RUN("test", "--test1", "-a");
|
||||
RUN("test", "--test2", "-a");
|
||||
|
||||
+4
-4
@@ -26,11 +26,11 @@ int main(void) {
|
||||
UNEXP_IF(close, cr, != 0);
|
||||
|
||||
// send 7 characters in the string, including end-of-string
|
||||
int bytes = write(pip[1], outstring, strlen(outstring));
|
||||
ssize_t bytes = write(pip[1], outstring, strlen(outstring));
|
||||
ERROR_IF(write, bytes, == -1);
|
||||
|
||||
// check result
|
||||
if (bytes != strlen(outstring)) {
|
||||
if ((size_t)bytes != strlen(outstring)) {
|
||||
fprintf(stderr, "pipe write: %d != %ld\n", bytes, strlen(outstring));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -52,11 +52,11 @@ int main(void) {
|
||||
memset(instring, 0, sizeof(instring));
|
||||
|
||||
// read from the pipe
|
||||
int bytes = read(pip[0], instring, sizeof(instring) - 1);
|
||||
ssize_t bytes = read(pip[0], instring, sizeof(instring) - 1);
|
||||
ERROR_IF(read, bytes, == -1);
|
||||
|
||||
// check result
|
||||
if (bytes != strlen(outstring)) {
|
||||
if ((size_t)bytes != strlen(outstring)) {
|
||||
fprintf(stderr, "pipe read: %d != %ld\n", bytes, strlen(outstring));
|
||||
exit(EXIT_FAILURE);
|
||||
} else if (memcmp(instring, outstring, strlen(outstring)) != 0) {
|
||||
|
||||
+6
-7
@@ -1,15 +1,14 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
|
||||
int main(void) {
|
||||
const char source[] = {0, 1, 2, 3, 4, 5, 6};
|
||||
char destination[] = {0, 0, 0, 0, 0, 0};
|
||||
const char flipped_source[] = {1, 0, 3, 2, 5, 4};
|
||||
const char first_two_source_bytes_flipped[] = {1, 0};
|
||||
|
||||
swab(source, destination, /* nbytes */ -3);
|
||||
for (int i = 0; i < sizeof(destination); ++i) {
|
||||
for (size_t i = 0; i < sizeof(destination); ++i) {
|
||||
if (destination[i] != 0) {
|
||||
puts("If nbytes is negative destionation shouldn't be modified");
|
||||
return 1;
|
||||
@@ -17,7 +16,7 @@ int main(int argc, char ** argv) {
|
||||
}
|
||||
|
||||
swab(source, destination, /* nbytes */ 0);
|
||||
for (int i = 0; i < sizeof(destination); ++i) {
|
||||
for (size_t i = 0; i < sizeof(destination); ++i) {
|
||||
if (destination[i] != 0) {
|
||||
puts("If nbytes is zero destionation shouldn't be modified");
|
||||
return 1;
|
||||
@@ -25,7 +24,7 @@ int main(int argc, char ** argv) {
|
||||
}
|
||||
|
||||
swab(source, destination, /* nbytes */ 3);
|
||||
for (int i = 0; i < sizeof(first_two_source_bytes_flipped); ++i) {
|
||||
for (size_t i = 0; i < sizeof(first_two_source_bytes_flipped); ++i) {
|
||||
if (destination[i] != first_two_source_bytes_flipped[i]) {
|
||||
puts("copied bytes don't match expected values");
|
||||
return 1;
|
||||
@@ -33,7 +32,7 @@ int main(int argc, char ** argv) {
|
||||
}
|
||||
// If nbytes is not even it's not specified what should happen to the
|
||||
// last byte so the third byte in destination is not checked.
|
||||
for (int i = sizeof(first_two_source_bytes_flipped) + 1; i < sizeof(destination); ++i) {
|
||||
for (size_t i = sizeof(first_two_source_bytes_flipped) + 1; i < sizeof(destination); ++i) {
|
||||
if (destination[i] != 0) {
|
||||
puts("swab modified too many bytes in destination");
|
||||
return 1;
|
||||
@@ -41,7 +40,7 @@ int main(int argc, char ** argv) {
|
||||
}
|
||||
|
||||
swab(source, destination, /* nbytes */ sizeof(destination));
|
||||
for (int i = 0; i < sizeof(destination); ++i) {
|
||||
for (size_t i = 0; i < sizeof(destination); ++i) {
|
||||
if (destination[i] != flipped_source[i]) {
|
||||
puts("copied bytes don't match expected values");
|
||||
return 1;
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ int main() {
|
||||
&test_manual_wchar_orientation,
|
||||
&test_orientation_after_fprintf,
|
||||
};
|
||||
for(int i=0; i<sizeof(tests)/sizeof(int(*)(void)); i++) {
|
||||
for(size_t i = 0; i < sizeof(tests) / sizeof(int(*)(void)); i++) {
|
||||
printf("%d\n", (*tests[i])());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
@@ -5,7 +6,7 @@
|
||||
int main() {
|
||||
wchar_t *str = L"HaLf WiDe ChAr StRiNg!\n";
|
||||
fputws(str, stdout);
|
||||
for (int i = 0; i < wcslen(str); i++) {
|
||||
for (size_t i = 0; i < wcslen(str); i++) {
|
||||
putwchar(towctrans(str[i], wctrans("tolower")));
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
|
||||
int main() {
|
||||
wchar_t *str = L"HaLf WiDe ChAr StRiNg!\n";
|
||||
fputws(str, stdout);
|
||||
for (int i = 0; i < wcslen(str); i++) {
|
||||
for (size_t i = 0; i < wcslen(str); i++) {
|
||||
putwchar(towctrans(str[i], wctrans("toupper")));
|
||||
}
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user