Bug Exercises Part II: Patching

Today’s exercises involve one of the more basic skills that all programmers should know: patching. In the open source world patching has become pretty standardized, except for certain minutiae in formatting. So for the exercise my job was to create some test patches and understand the test process using the Unix terminal.


This exercise was creating a basic diff output using none other than the diff command. The output of this diff corresponded to the books results and is reprinted below.

steve@ubuntu:~$ diff -u hello.c hello.c.punct

— hello.c 2012-02-09 23:50:18.659577870 -0500

+++ hello.c.punct 2012-02-09 23:51:37.780125196 -0500

@@ -5,6 +5,6 @@


int main() {

– printf(“Hello, World.\n”);

+ printf(“Hello, World!\n”);

return 0;


Then the next exercise was to examine the differences made by not having a -u. By not having the -u we see that the formatting of the output has changed. There is less information and is more bare representation.

steve@ubuntu:~$ diff hello.c hello.c.punct


printf(“Hello, World!\n”);

This exercise was the creation of patch file containing the word bar. First I created the file “foo” containing “bar” and used diff on it with the null file provided by Unix. The resulting output was created in a file named “foopatch.patch”. Redundant I know. Just did not want to lose the foo.c

— foo.txt 2012-02-09 23:58:58.439593808 -0500
+++ /dev/null 2012-02-09 23:48:23.021831997 -0500
@@ -1 +0,0 @@

Finally this exercise had me making a patch file using a real program. The program is called caultelis. I took the echo.c file and changed a small snippet of code to compare to echo.c.reverse. The following output was created, which matches the output the book says I will get.

— src/echo.c.reverse 2012-02-10 00:06:29.018333108 -0500
+++ src/echo.c 2012-02-10 00:10:10.938330675 -0500
@@ -258,14 +258,14 @@
– while (argc > 0)
+ while (argc > 0)
– fputs (argv[0], stdout);
– argv++;
+ fputs (argv[argc], stdout);
if (argc > 0)
putchar (‘ ‘);

if (display_return)

These exercises were a great experience. Considering we have our first bug fix due Monday I was glad to get this practice in for making a patch to my team’s Drupal project. This weekend I will update the results of creating my first official patch for Drupal.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s