{"thread":{"id":"3822","subject":"realloc","startedAt":"2006-04-07T20:11:21Z","lastAt":"2006-04-07T20:35:30Z","messageCount":2,"participants":["Morten Welinder","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"18455","messageId":"118833cc0604071311v1da93f83n112cc2ea44552ca9@mail.gmail.com","threadId":"3822","inReplyTo":null,"subject":"realloc","fromName":"Morten Welinder","fromEmail":"mwelinder@gmail.com","sentAt":"2006-04-07T20:11:21Z","receivedAt":"2006-04-07T20:11:21Z","isPatch":false,"sender":{"key":"mwelinder@gmail.com","avatar":null},"body":"I could be wrong, but shouldn't\n\n      var = realloc (var, whatever);\n\nbe changed to call xrealloc?  That, or assign to a different variable and check\nfor NULL.\n\nThis should affect the last four hits below.\n\nM.\n\n\n\n\n/scratch/welinder/git> grep -w realloc *.c\ndaemon.c:               newlist = realloc(socklist, sizeof(int) *\n(socknum + 1));\ndiff-delta.c:                           out = realloc(out, outsize);\ngit.c:          cmdname = realloc(cmdname, cmdname_alloc * sizeof(*cmdname));\nls-files.c:             which->excludes = realloc(which->excludes,\nsha1_file.c:                            buf = realloc(buf, size);\n"},{"id":"18456","messageId":"7vmzexi0od.fsf@assigned-by-dhcp.cox.net","threadId":"3822","inReplyTo":"118833cc0604071311v1da93f83n112cc2ea44552ca9@mail.gmail.com","subject":"Re: realloc","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-04-07T20:35:30Z","receivedAt":"2006-04-07T20:35:30Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Morten Welinder\" <mwelinder@gmail.com> writes:\n\n> I could be wrong, but shouldn't\n>\n>       var = realloc (var, whatever);\n>\n> be changed to call xrealloc?  That, or assign to a different variable and check\n> for NULL.\n>\n> This should affect the last four hits below.\n>\n> M.\n>\n>\n>\n>\n> /scratch/welinder/git> grep -w realloc *.c\n> daemon.c:               newlist = realloc(socklist, sizeof(int) *\n> (socknum + 1));\n> diff-delta.c:                           out = realloc(out, outsize);\n> git.c:          cmdname = realloc(cmdname, cmdname_alloc * sizeof(*cmdname));\n> ls-files.c:             which->excludes = realloc(which->excludes,\n> sha1_file.c:                            buf = realloc(buf, size);\n\nThere is no excuse for not using xrealloc() in git.c,\nls-files.c, and sha1_file.c.\n\nThe diff-delta.c code wants to be independent from the rest of\ngit code, so it probably should check the returned value itself.\n\nHistorically to a certain degree daemon.c also wanted to be\nindependent from the rest of git, but I suspect it still is the\ncase (it uses small pieces from packet interface but that is\nabout it).\n"}]}