Guest User

Untitled

a guest
Aug 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. c program dumping core on unix
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4.  
  5. void main()
  6. {
  7. char *name;
  8. name="James Bond";
  9. int i=0;
  10. sprintf(name,"%s/%d",name,i);
  11. printf("String is %s",name);
  12. }
  13.  
  14. #include <stdio.h>
  15.  
  16. int main (void) {
  17. char *name;
  18. char name2[100]; // make sure plenty of space.
  19. name = "James Bond";
  20. int i = 0;
  21. sprintf (name2, "%s/%d", name, i);
  22. printf ("String is %sn", name2);
  23. return 0;
  24. }
  25.  
  26. name = "Bob";
  27. *name = 'J'; // to try and make "Job"
  28.  
  29. char *path = "/tmp/";
  30. char *file = "xyz.txt"
  31. char fullpath = malloc (strlen (path) + strlen (file) + 1);
  32. if (fullpath == NULL)
  33. // error and exit condition
  34. strcpy (fullpath, path);
  35. strcat (fullpath, file);
  36. // use fullpath for your nefarious purposes :-)
  37. free (fullpath);
  38.  
  39. char name[]="James Bond";
  40.  
  41. #include<stdio.h>
  42. #include<stdlib.h>
  43. void main()
  44. {
  45. char name[] = "James Bond";
  46. int i = 0;
  47.  
  48. printf("String is %s/%d", name,i);
  49.  
  50. }
  51.  
  52. char *name;
  53. name="James Bond"; // name is pointing into read-only memory
  54. int i=0;
  55. sprintf(name,"%s/%d",name,i); // trying to write to read-only memory
  56. printf("String is %s",name);
  57.  
  58. char name[32] = "James Bond";
  59. ...
  60.  
  61. char* str = NULL; // pointer should be initialized to NULL
  62. asprintf (&str, "someformat %d", 20);
Add Comment
Please, Sign In to add comment