[Python-checkins] cpython: Avoid useless "++" at the end of functions

Eric Smith eric at trueblade.com
Thu May 26 14:13:16 CEST 2011


We've been through this before, and I think we decided to leave code
like this as-is. I know I'd personally much prefer these increments to
stay in the code.

If you're ever going to add code at the end of these functions, it's
unlikely you'll remember that you need to add these increments back in.
It's a bug waiting to happen, and I don't see any harm leaving them in.
Maybe we should add a comment about why they're done.

Eric.

On 5/26/2011 8:07 AM, victor.stinner wrote:
> http://hg.python.org/cpython/rev/7ba176c2f558
> changeset:   70397:7ba176c2f558
> user:        Victor Stinner <victor.stinner at haypocalc.com>
> date:        Thu May 26 13:53:47 2011 +0200
> summary:
>   Avoid useless "++" at the end of functions
> 
> Warnings found by the Clang Static Analyzer.
> 
> files:
>   Objects/setobject.c     |  4 ++--
>   Objects/unicodeobject.c |  2 +-
>   Python/compile.c        |  6 +++---
>   3 files changed, 6 insertions(+), 6 deletions(-)
> 
> 
> diff --git a/Objects/setobject.c b/Objects/setobject.c
> --- a/Objects/setobject.c
> +++ b/Objects/setobject.c
> @@ -612,9 +612,9 @@
>          *u++ = '{';
>          /* Omit the brackets from the listrepr */
>          Py_UNICODE_COPY(u, PyUnicode_AS_UNICODE(listrepr)+1,
> -                           PyUnicode_GET_SIZE(listrepr)-2);
> +                           newsize-2);
>          u += newsize-2;
> -        *u++ = '}';
> +        *u = '}';
>      }
>      Py_DECREF(listrepr);
>      if (Py_TYPE(so) != &PySet_Type) {
> diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
> --- a/Objects/unicodeobject.c
> +++ b/Objects/unicodeobject.c
> @@ -6474,7 +6474,7 @@
>          }
>      }
>      /* 0-terminate the output string */
> -    *output++ = '\0';
> +    *output = '\0';
>      Py_XDECREF(exc);
>      Py_XDECREF(errorHandler);
>      return 0;
> diff --git a/Python/compile.c b/Python/compile.c
> --- a/Python/compile.c
> +++ b/Python/compile.c
> @@ -3747,11 +3747,11 @@
>      a->a_lnotab_off += 2;
>      if (d_bytecode) {
>          *lnotab++ = d_bytecode;
> -        *lnotab++ = d_lineno;
> +        *lnotab = d_lineno;
>      }
>      else {      /* First line of a block; def stmt, etc. */
>          *lnotab++ = 0;
> -        *lnotab++ = d_lineno;
> +        *lnotab = d_lineno;
>      }
>      a->a_lineno = i->i_lineno;
>      a->a_lineno_off = a->a_offset;
> @@ -3796,7 +3796,7 @@
>      if (i->i_hasarg) {
>          assert(size == 3 || size == 6);
>          *code++ = arg & 0xff;
> -        *code++ = arg >> 8;
> +        *code = arg >> 8;
>      }
>      return 1;
>  }
> 
> 
> 
> 
> _______________________________________________
> Python-checkins mailing list
> Python-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-checkins



More information about the Python-checkins mailing list