{"thread":{"id":"850","subject":"duplicate htons() in check_file_directory_conflict()","startedAt":"2005-06-06T23:02:46Z","lastAt":"2005-06-07T20:35:56Z","messageCount":3,"participants":["Timo Hirvonen","Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"4660","messageId":"1118098966l.5384l.0l@garlic","threadId":"850","inReplyTo":null,"subject":"duplicate htons() in check_file_directory_conflict()","fromName":"Timo Hirvonen","fromEmail":"tihirvon@ee.oulu.fi","sentAt":"2005-06-06T23:02:46Z","receivedAt":"2005-06-06T23:02:46Z","isPatch":false,"sender":{"key":"tihirvon@gmail.com","avatar":null},"body":"Hi,\n\ncreate_ce_flags() macro calls htons() so the htons()s in  \ncheck_file_directory_conflict() should be removed or alternatively htons  \nshould be removed from the create_ce_flags macro. I noticed the bug when  \ncompiling cogito with -Wshadow.\n\nread-cache.c:208\n        pos = cache_name_pos(pathbuf,\n                             htons(create_ce_flags(len, stage)));\n\n\nread-cache.c:232\n        pos = cache_name_pos(path,\n                             htons(create_ce_flags(namelen, stage)));\n\n-- \nhttp://onion.dynserv.net/~timo/\n\n\n"},{"id":"4661","messageId":"Pine.LNX.4.58.0506061858140.1876@ppc970.osdl.org","threadId":"850","inReplyTo":"1118098966l.5384l.0l@garlic","subject":"Re: duplicate htons() in check_file_directory_conflict()","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-06-07T01:59:18Z","receivedAt":"2005-06-07T01:59:18Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Mon, 6 Jun 2005, Timo Hirvonen wrote:\n>\n> create_ce_flags() macro calls htons() so the htons()s in  \n> check_file_directory_conflict() should be removed or alternatively htons  \n> should be removed from the create_ce_flags macro. I noticed the bug when  \n> compiling cogito with -Wshadow.\n\nNo, but it probably should be a ntohs()..\n\ncache_name_pos() takes a host-order thing, and create_ce_flags creates a \nnetwork order thing. It so happens that on all sane setups, ntohs == \nhtons, so..\n\n\t\tLinus\n"},{"id":"4680","messageId":"1118176556l.5398l.1l@garlic","threadId":"850","inReplyTo":"Pine.LNX.4.58.0506061858140.1876@ppc970.osdl.org","subject":"[PATCH] Use ntohs instead of htons to convert ce_flags to host byte order","fromName":"Timo Hirvonen","fromEmail":"tihirvon@ee.oulu.fi","sentAt":"2005-06-07T20:35:56Z","receivedAt":"2005-06-07T20:35:56Z","isPatch":true,"sender":{"key":"tihirvon@gmail.com","avatar":null},"body":"Use ntohs instead of htons to convert ce_flags to host byte order\n\n---\ncommit f827ec4fa1be102bda5b92edbf380defa03e8ae2\ntree 735922d31ccdc6a2dc1f8e3f1388445903542385\nparent fd787bb8d89cdacedc16cfef9dc4feb0cf843def\nauthor Timo Hirvonen <tihirvon@ee.oulu.fi> Tue, 07 Jun 2005 23:18:02 +0300\ncommitter Timo Hirvonen <tihirvon@ee.oulu.fi> Tue, 07 Jun 2005 23:18:02 +0300\n\n read-cache.c |   10 +++++-----\n 1 files changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/read-cache.c b/read-cache.c\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -132,7 +132,7 @@ int cache_name_pos(const char *name, int\n \twhile (last > first) {\n \t\tint next = (last + first) >> 1;\n \t\tstruct cache_entry *ce = active_cache[next];\n-\t\tint cmp = cache_name_compare(name, namelen, ce->name, htons(ce->ce_flags));\n+\t\tint cmp = cache_name_compare(name, namelen, ce->name, ntohs(ce->ce_flags));\n \t\tif (!cmp)\n \t\t\treturn next;\n \t\tif (cmp < 0) {\n@@ -206,7 +206,7 @@ static int check_file_directory_conflict\n \t\t*ep = 0;    /* first cut it at slash */\n \t\tlen = ep - pathbuf;\n \t\tpos = cache_name_pos(pathbuf,\n-\t\t\t\t     htons(create_ce_flags(len, stage)));\n+\t\t\t\t     ntohs(create_ce_flags(len, stage)));\n \t\tif (0 <= pos) {\n \t\t\t/* Our leading path component is registered as a file,\n \t\t\t * and we are trying to make it a directory.  This is\n@@ -230,7 +230,7 @@ static int check_file_directory_conflict\n \t * a directory there?\n \t */\n \tpos = cache_name_pos(path,\n-\t\t\t     htons(create_ce_flags(namelen, stage)));\n+\t\t\t     ntohs(create_ce_flags(namelen, stage)));\n \n \t/* (0 <= pos) cannot happen because add_cache_entry()\n \t * should have taken care of that case.\n@@ -279,7 +279,7 @@ int add_cache_entry(struct cache_entry *\n \tint pos;\n \tint ok_to_add = option & ADD_CACHE_OK_TO_ADD;\n \tint ok_to_replace = option & ADD_CACHE_OK_TO_REPLACE;\n-\tpos = cache_name_pos(ce->name, htons(ce->ce_flags));\n+\tpos = cache_name_pos(ce->name, ntohs(ce->ce_flags));\n \n \t/* existing match? Just replace it */\n \tif (pos >= 0) {\n@@ -307,7 +307,7 @@ int add_cache_entry(struct cache_entry *\n \tif (check_file_directory_conflict(ce, ok_to_replace)) {\n \t\tif (!ok_to_replace)\n \t\t\treturn -1;\n-\t\tpos = cache_name_pos(ce->name, htons(ce->ce_flags));\n+\t\tpos = cache_name_pos(ce->name, ntohs(ce->ce_flags));\n \t\tpos = -pos-1;\n \t}\n \n\n\n\n"}]}