Linuxでwdiffを使うとエラーが出る場合
wdiffと言う単語単位で差分をとれるものがある。これをLinuxにインストールしようとするとエラーが。wdiff-0.5/wdiff.c:569: warning: the use of `tmpnam' is dangerous, better use `mkstemp'いろいろ検索してこれを出ないようにwdiff.cを変更。で、makeした後にwdiffのチェック。今度はメモリに関するエラーが。*** glibc detected *** ./wdiff: corrupted double-linked list: 0x09e40000 ***======= Backtrace: =========…======= Memory map: ========…これもいろいろ検索して、ようやくエラーが出ないようにできた。苦戦したのでパッチを作成。下のソースをコピーして、wdiffのソースディレクトリにwdiff.c.patchとして保存。patch -p0 < wdiff.c.patchでOK。あとは、./configure, make, make install。--- wdiff.c.original 1994-11-06 16:57:23.000000000 +0900+++ wdiff.c 2009-09-25 15:48:22.000000000 +0900@@ -555,6 +555,7 @@ split_file_into_words (SIDE *side) { struct stat stat_buffer; /* for checking if file is directory */+ int fd; /* for file descriptors returned by mkstemp */ /* Open files. */ @@ -566,8 +567,11 @@ this temporary local file. Once done, prepare it for reading. We do not need the file name itself anymore. */ - tmpnam (side->temp_name);- side->file = fopen (side->temp_name, "w+");+ // tmpnam (side->temp_name);+ // side->file = fopen (side->temp_name, "w+");+ strcpy(side->temp_name, "/tmp/wdiff.XXXXXX");+ fd = mkstemp(side->temp_name);+ side->file = fdopen(fd, "w+"); if (side->file == NULL) error (EXIT_OTHER_REASON, errno, side->temp_name); if (unlink (side->temp_name) != 0)@@ -593,8 +597,11 @@ side->character = getc (side->file); side->position = 0; - tmpnam (side->temp_name);- side->temp_file = fopen (side->temp_name, "w");+ // tmpnam (side->temp_name);+ // side->temp_file = fopen (side->temp_name, "w");+ strcpy(side->temp_name, "/tmp/wdiff.XXXXXX");+ fd = mkstemp(side->temp_name);+ side->temp_file = fdopen(fd, "w"); if (side->temp_file == NULL) error (EXIT_OTHER_REASON, errno, side->temp_name); @@ -877,7 +884,9 @@ /* Close input files. */ fclose (left_side->file);+ left_side->file = NULL; fclose (right_side->file);+ right_side->file = NULL; } @@ -910,7 +919,12 @@ static void complete_input_program (void) {- fclose (input_file);+ // fclose (input_file);+ if (input_file)+ {+ fclose (input_file);+ input_file = NULL;+ } wait (NULL); } @@ -1302,7 +1316,12 @@ launch_output_program (); initialize_strings (); reformat_diff_output ();- fclose (input_file);+ // fclose (input_file);+ if (input_file)+ {+ fclose (input_file);+ input_file = NULL;+ } } /* Clean up. Beware that input_file and output_file might not exist,