Yoichi's diary
2013-01-04
_ [comp/Windows] Windows7 で Skype がタスクバーに居座ることへの対処
以前検索したら互換モードで動かせとかいう方法が紹介されてて驚いたが、調べなおしたらちゃんと設定項目であるじゃないか。 How to Minimize Skype to Windows 7 System Tray (Notification Area)[ツッコミを入れる]
2013-01-20
_ [zsh] disable r
そもそも r を定義してるってことを知らなかった。意図せず実行しちゃうのが怖いので無効化しといた。 `r`コマンドと言えば、統計だよねという全ての人のために - zshデフォルトの`r`コマンドをオフにする方法[ツッコミを入れる]
2013-01-27
_ [C] 可変長引数マクロ
sample1.c:#include <stdio.h> #include <string.h> #define LOG_PRINT(fmt,...) printf(fmt "@%s:%d\n", __VA_ARGS__, __FILE__, __LINE__) void Sample(int a) { LOG_PRINT(); LOG_PRINT("log without argument"); LOG_PRINT("log with argument %d", a); }cl では警告出しつつもコンパイル通る
>cl /P sample1.c ... sample1.c(6) : warning C4003: マクロ 'LOG_PRINT' に指定された実引数の数が少なすぎます。 >type sample1.i ... void Sample(int a) { printf( "@%s:%d\n" , "sample1.c", 6); printf("log without argument" "@%s:%d\n" , "sample1.c", 7); printf("log with argument %d" "@%s:%d\n", a, "sample1.c", 8); }gcc だと , が残ってコンパイルエラーになる。
% gcc -c sample1.c sample1.c: In function ‘Sample’: sample1.c:6:2: error: expected expression before ‘,’ token sample1.c:7:2: error: expected expression before ‘,’ token % gcc -E sample1.c ... void Sample(int a) { printf( "@%s:%d\n", , "sample1.c", 6); printf("log without argument" "@%s:%d\n", , "sample1.c", 7); printf("log with argument %d" "@%s:%d\n", a, "sample1.c", 8); }gcc 拡張の ## を使うとよきに計らってくれる。sample2.c:
#include <stdio.h> #include <string.h> #define LOG_PRINT(fmt,...) printf(fmt "@%s:%d\n", ##__VA_ARGS__, __FILE__, __LINE__) void Sample(int a) { LOG_PRINT(); LOG_PRINT("log without argument"); LOG_PRINT("log with argument %d", a); }
% gcc -E sample2.c ... void Sample(int a) { printf( "@%s:%d\n" , "sample1.c", 6); printf("log without argument" "@%s:%d\n" , "sample1.c", 7); printf("log with argument %d" "@%s:%d\n", a, "sample1.c", 8); }(なお、マクロ展開結果を見るためのコマンドラインオプションのメモが主目的だったりします)
[ツッコミを入れる]
2013-01-30
_ [comp] Portable SDK for UPnP Devices (libupnp) contains multiple buffer overflows in SSDP
しばらく追いかけてなかったのだけど、同僚から声をかけられて修正箇所の blame したらいじった箇所が入ってて血の気引いた。帰宅後に落ち着いて見なおして、やってしまったわけではないことが確認できてほっとした。教訓:- 警告を抑えこむときは慎重に (openssl と debian の話を忘れるな)
- バッファ長チェックの条件が本当に意味をなしているか自問しよう
- ネットワークライブラリは怖い
[ツッコミを入れる]