]> Savannah Git Hosting - gnulib.git/commitdiff
argp: Simplify bit manipulation.
authorBruno Haible <bruno@clisp.org>
Sun, 21 May 2017 00:46:18 +0000 (02:46 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 21 May 2017 00:46:18 +0000 (02:46 +0200)
* lib/argp-parse.c (parser_parse_opt): Use &, |, ~ instead of shifts
on a signed integer type.

ChangeLog
lib/argp-parse.c

index 8ebdd7b5d0000c9032e67d61919b36bb4e2bac88..541952e4920c1f00f793a6c44f359a6cf9f86e44 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-05-20  Bruno Haible  <bruno@clisp.org>
+
+       argp: Simplify bit manipulation.
+       * lib/argp-parse.c (parser_parse_opt): Use &, |, ~ instead of shifts
+       on a signed integer type.
+
 2017-05-20  Bruno Haible  <bruno@clisp.org>
 
        Avoid wrong configure results with gcc -fsanitize=address.
index 4723a2b29dda9e4eebec549a882018b064565c90..fb04a4a2f9b71b2d79077712429ff045a1d58b41 100644 (file)
@@ -743,15 +743,8 @@ parser_parse_opt (struct parser *parser, int opt, char *val)
     /* A long option.  Preserve the sign in the user key, without
        invoking undefined behavior.  Assume two's complement.  */
     {
-      unsigned uopt = opt;
-      unsigned ushifted_user_key = uopt << GROUP_BITS;
-      int shifted_user_key = ushifted_user_key;
-      int user_key;
-      if (-1 >> 1 == -1)
-        user_key = shifted_user_key >> GROUP_BITS;
-      else
-        user_key = ((ushifted_user_key >> GROUP_BITS)
-                    - (shifted_user_key < 0 ? 1 << USER_BITS : 0));
+      int user_key =
+        ((opt & (1 << (USER_BITS - 1))) ? ~USER_MASK : 0) | (opt & USER_MASK);
       err =
         group_parse (&parser->groups[group_key - 1], &parser->state,
                      user_key, parser->opt_data.optarg);