author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Fri, 27 Dec 2013 16:00:09 +0100 | |
changeset 167 | 7c6b221900bf |
parent 114 | 6f6850407ccf |
permissions | -rw-r--r-- |
0 | 1 |
/** |
77 | 2 |
* utf8.c |
9
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
8
diff
changeset
|
3 |
* Copyright (C) 2008 Markus Broeker |
0 | 4 |
*/ |
5 |
||
6 |
#include <stdio.h> |
|
7 |
#include <stdlib.h> |
|
8 |
#include <wchar.h> |
|
9 |
#include <locale.h> |
|
114
6f6850407ccf
buffer overflow in utf8 and ncurses demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
10 |
#include <string.h> |
0 | 11 |
|
12 |
#ifndef u_char |
|
13 |
typedef unsigned char u_char; |
|
14 |
#endif |
|
15 |
||
16 |
int main () |
|
17 |
{ |
|
114
6f6850407ccf
buffer overflow in utf8 and ncurses demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
18 |
char dest[6]; |
0 | 19 |
|
20 |
wchar_t *str = L"Unicode Example with german umlauts: ÄÖÜäöü߀\n"; |
|
21 |
||
22 |
if (!setlocale (LC_CTYPE, "")) { |
|
23 |
perror ("SETLOCALE"); |
|
24 |
return EXIT_FAILURE; |
|
25 |
} |
|
26 |
||
27 |
printf ("%ls", str); |
|
28 |
||
114
6f6850407ccf
buffer overflow in utf8 and ncurses demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
29 |
while (*str != L'\n') { |
6f6850407ccf
buffer overflow in utf8 and ncurses demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
30 |
memset (&dest, 0, sizeof (dest)); |
6f6850407ccf
buffer overflow in utf8 and ncurses demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
31 |
if (wctomb (dest, (*str)) < 0) |
6f6850407ccf
buffer overflow in utf8 and ncurses demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
32 |
perror ("wctomb"); |
0 | 33 |
|
34 |
printf ("%lc -> [%4X] (%2X:%2X:%2X:%2X)\n", |
|
35 |
*str, *str, (u_char) dest[0], (u_char) dest[1], (u_char) dest[2], (u_char) dest[3]); |
|
36 |
str++; |
|
37 |
} |
|
38 |
||
39 |
printf ("DIFF: %d : 0x%2X\n", 0x40, 0x40); |
|
8
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
40 |
|
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
41 |
return EXIT_SUCCESS; |
0 | 42 |
} |