[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: af_alg: Comment and style improvements

From: Paul Eggert
Subject: Re: af_alg: Comment and style improvements
Date: Mon, 25 Jun 2018 10:52:23 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0

On 06/24/2018 03:28 PM, Bruno Haible wrote:
-  /* Avoid calling both strcpy and strlen.  */
-  for (int i = 0; (salg.salg_name[i] = alg[i]); i++)
+  /* Copy alg into salg.salg_name, without calling strcpy nor strlen.  */
+  for (size_t i = 0; (salg.salg_name[i] = alg[i]) != '\0'; i++)

I prefer to use signed integer types when possible, as it allows better runtime checking (for integer overflow). This is a style encouraged within Emacs and I'd like to encourage it elsewhere too.

If you don't like int due to concerns about too-large sizes (of course theoretical in this case, but here we are...), then how about ptrdiff_t instead? ptrdiff_t should be always safe, since programs should never create objects larger than PTRDIFF_MAX anyway (as they'd get undefined behavior with pointer subtraction otherwise).

A nit: that "nor" should be "or".

reply via email to

[Prev in Thread] Current Thread [Next in Thread]