{"thread":{"id":"50869","subject":"[PATCH 0/2] create FLEX_ALLOC_MEM to FLEX_ALLOC_STR cocci rule","startedAt":"2019-04-03T22:00:08Z","lastAt":"2019-04-04T01:57:03Z","messageCount":4,"participants":["Denton Liu","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"373073","messageId":"cover.1554328261.git.liu.denton@gmail.com","threadId":"50869","inReplyTo":null,"subject":"[PATCH 0/2] create FLEX_ALLOC_MEM to FLEX_ALLOC_STR cocci rule","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-04-03T22:00:03Z","receivedAt":"2019-04-03T22:00:08Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"I was playing around with coccinelle and I noticed that we have a use of\nFLEX_ALLOC_MEM that could be converted into FLEX_ALLOC_STR. Convert it\nand write a cocci rule to prevent this from happening.\n\nNote that this was more of an exercise to teach myself how to use\ncoccinelle. I'm just submitting a useful patch that came as a result of\nthis. Please let me know if this is unwelcome.\n\nDenton Liu (2):\n  midx.c: convert FLEX_ALLOC_MEM to FLEX_ALLOC_STR\n  cocci: FLEX_ALLOC_MEM to FLEX_ALLOC_STR\n\n contrib/coccinelle/flex_alloc.cocci | 13 +++++++++++++\n midx.c                              |  2 +-\n 2 files changed, 14 insertions(+), 1 deletion(-)\n create mode 100644 contrib/coccinelle/flex_alloc.cocci\n\n-- \n2.21.0.834.geaa57a21fa\n\n"},{"id":"373074","messageId":"48c968a2923f76ab759327d21b37de86f7a61236.1554328261.git.liu.denton@gmail.com","threadId":"50869","inReplyTo":"cover.1554328261.git.liu.denton@gmail.com","subject":"[PATCH 1/2] midx.c: convert FLEX_ALLOC_MEM to FLEX_ALLOC_STR","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-04-03T22:00:05Z","receivedAt":"2019-04-03T22:00:09Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Signed-off-by: Denton Liu <liu.denton@gmail.com>\n---\n midx.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/midx.c b/midx.c\nindex 8a505fd423..cb8190329a 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -70,7 +70,7 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local\n \n \tmidx_map = xmmap(NULL, midx_size, PROT_READ, MAP_PRIVATE, fd, 0);\n \n-\tFLEX_ALLOC_MEM(m, object_dir, object_dir, strlen(object_dir));\n+\tFLEX_ALLOC_STR(m, object_dir, object_dir);\n \tm->fd = fd;\n \tm->data = midx_map;\n \tm->data_len = midx_size;\n-- \n2.21.0.834.geaa57a21fa\n\n"},{"id":"373075","messageId":"78b6d3f58dc409477e801aa3d83e83ccee3841cb.1554328261.git.liu.denton@gmail.com","threadId":"50869","inReplyTo":"cover.1554328261.git.liu.denton@gmail.com","subject":"[PATCH 2/2] cocci: FLEX_ALLOC_MEM to FLEX_ALLOC_STR","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-04-03T22:00:06Z","receivedAt":"2019-04-03T22:00:16Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Ensure that a FLEX_MALLOC_MEM that uses 'strlen' for its 'len' uses\nFLEX_ALLOC_STR instead, since these are equivalent forms.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n contrib/coccinelle/flex_alloc.cocci | 13 +++++++++++++\n 1 file changed, 13 insertions(+)\n create mode 100644 contrib/coccinelle/flex_alloc.cocci\n\ndiff --git a/contrib/coccinelle/flex_alloc.cocci b/contrib/coccinelle/flex_alloc.cocci\nnew file mode 100644\nindex 0000000000..e9f7f6d861\n--- /dev/null\n+++ b/contrib/coccinelle/flex_alloc.cocci\n@@ -0,0 +1,13 @@\n+@@\n+expression str;\n+identifier x, flexname;\n+@@\n+- FLEX_ALLOC_MEM(x, flexname, str, strlen(str));\n++ FLEX_ALLOC_STR(x, flexname, str);\n+\n+@@\n+expression str;\n+identifier x, ptrname;\n+@@\n+- FLEXPTR_ALLOC_MEM(x, ptrname, str, strlen(str));\n++ FLEXPTR_ALLOC_STR(x, ptrname, str);\n-- \n2.21.0.834.geaa57a21fa\n\n"},{"id":"373086","messageId":"20190404015659.GE4409@sigill.intra.peff.net","threadId":"50869","inReplyTo":"cover.1554328261.git.liu.denton@gmail.com","subject":"Re: [PATCH 0/2] create FLEX_ALLOC_MEM to FLEX_ALLOC_STR cocci rule","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-04-04T01:57:00Z","receivedAt":"2019-04-04T01:57:03Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Apr 03, 2019 at 03:00:03PM -0700, Denton Liu wrote:\n\n> I was playing around with coccinelle and I noticed that we have a use of\n> FLEX_ALLOC_MEM that could be converted into FLEX_ALLOC_STR. Convert it\n> and write a cocci rule to prevent this from happening.\n> \n> Note that this was more of an exercise to teach myself how to use\n> coccinelle. I'm just submitting a useful patch that came as a result of\n> this. Please let me know if this is unwelcome.\n\nBoth look pretty reasonable to me. Obviously it's a pretty trivial\nchange, but that's sort of the point: automate these things away so we\ndon't have to think about them during review.\n\nNow if you could figure out a way to point people to FLEX_ALLOC in the\nfirst place when they are not currently using it, _that_ would be pretty\namazing. But I suspect it's a bit too complicated. :)\n\n-Peff\n"}]}