# HG changeset patch # User Markus Bröker # Date 1239878953 -7200 # Node ID 5a82f89d607ecbc3be7433e9d043d836574fe996 # Parent b7061c0e239f49599f510a4954dfaa542bf4826c uint vs size_t and two bugfixes in fak and unicode * Better Description of copy.cc * mem2swap throws a perror on failure committer: Markus Bröker diff --git a/atoi_print.c b/atoi_print.c --- a/atoi_print.c +++ b/atoi_print.c @@ -8,7 +8,7 @@ int main (int argc, char **argv) { - int i; + unsigned int i; for (i = 1; i < argc; i++) printf ("atoi(%s):=%d\n", argv[i], atoi (argv[i])); diff --git a/copy.cc b/copy.cc --- a/copy.cc +++ b/copy.cc @@ -15,7 +15,7 @@ char c; if (argc != 3) { - std::cout << "Benutzung: " << argv[0] << " " << std::endl; + std::cout << "Benutzung: " << argv[0] << " " << std::endl; return EXIT_SUCCESS; } diff --git a/duff.c b/duff.c --- a/duff.c +++ b/duff.c @@ -8,9 +8,9 @@ #include #include -char *duffcopy (char *to, char *from, int len) +char *duffcopy (char *to, char *from, size_t len) { - int n, pos = 0; + size_t n, pos = 0; n = (len + 7) / 8; @@ -49,7 +49,7 @@ int main (int argc, char **argv) { char *to, *from; - int len; + size_t len; if (argc != 2) { printf ("Usage: %s \n", argv[0]); diff --git a/fak.c b/fak.c --- a/fak.c +++ b/fak.c @@ -6,7 +6,7 @@ #include #include -long fak (int i) +unsigned long fak (short i) { if (i == 0) return 1; @@ -18,15 +18,20 @@ int main (int argc, char **argv) { - int number; + short number; printf ("Enter a number: "); - if (scanf ("%d", &number) < 0) { + if (scanf ("%hd", &number) != 1) { printf ("READ ERROR\n"); return EXIT_FAILURE; } - printf ("The faktorial of %d is %ld\n", number, fak (number)); + if (number < 0) { + printf ("NUMBER FORMAT ERROR\n"); + return EXIT_FAILURE; + } + + printf ("The faktorial of %d is %lu\n", number, fak (number)); return EXIT_SUCCESS; } diff --git a/floating.c b/floating.c --- a/floating.c +++ b/floating.c @@ -7,7 +7,7 @@ #include #include -double *getValues (int elements) +double *getValues (unsigned int elements) { double *values; int i; @@ -25,7 +25,7 @@ { double *values = getValues (MAX); - int i; + unsigned int i; for (i = 0; i < MAX; i++) { if (fabs (cos (i) - values[i]) < 0.001) diff --git a/mem2swap.c b/mem2swap.c --- a/mem2swap.c +++ b/mem2swap.c @@ -40,6 +40,8 @@ else { printf ("\tUsage: %s [MEM]\n\n", argv[0]); printf ("Report bugs to mbroeker@largo.homelinux.org\n"); + + perror ("Limit Error"); return EXIT_FAILURE; } diff --git a/myprintf.c b/myprintf.c --- a/myprintf.c +++ b/myprintf.c @@ -39,6 +39,7 @@ if ((ptr = realloc (s_str, ++size * BUF_SIZE)) == NULL) { s_str[pos] = '\0'; fputs (s_str, fp); /* print it anyway... */ + free (s_str); return EOF; } s_str = ptr; @@ -67,6 +68,7 @@ if (pos > (size * BUF_SIZE / 2)) { if ((ptr = realloc (s_str, ++size * BUF_SIZE)) == NULL) { + free (s_str); return EOF; } s_str = ptr; diff --git a/unicode.c b/unicode.c --- a/unicode.c +++ b/unicode.c @@ -11,11 +11,11 @@ #define FACTOR 1.42 -wchar_t *substr (const wchar_t * s, int start, int end) +wchar_t *substr (const wchar_t * s, size_t start, size_t end) { wchar_t *str; - int len = end - start; + size_t len = end - start; if (len < 1) return NULL;