progs/test.c
author cu
Mon, 23 Oct 2017 01:09:09 +0100
changeset 556 e6e87d5839c0
parent 211 e6e160c7ea33
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
203
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
#include <string.h>
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
#include <stdio.h>
211
e6e160c7ea33 added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
     3
//#include <stdlib.h>
203
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
void foo (char *bar)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
{
208
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
     7
  unsigned long my_long = 101010101;    // in hex: \xB5\x4A\x05\x06
203
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
  char  buffer[28];        
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
208
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
    10
  printf("my_long value = %lu\n", my_long);
203
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
  strcpy(buffer, bar);  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
 
208
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
    14
  printf("my_long value = %lu\n", my_long);
203
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
int main (int argc, char **argv)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
{
205
88416b7df38c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
    19
  foo("my string is too long !!!!!");                  // all is normal
88416b7df38c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
    20
  foo("my string is too long !!!!! \x15\xcd\x5b\x07"); // overwrites my_long
203
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
  return 0;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23