Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15231

expression evaluation problem

Path csiph.com!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!goblin3!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From L A Walsh <bash@tlinx.org>
Newsgroups gnu.bash.bug
Subject expression evaluation problem
Date Wed, 24 Jul 2019 09:39:46 -0700
Lines 33
Approved bug-bash@gnu.org
Message-ID <mailman.2152.1563986395.2688.bug-bash@gnu.org> (permalink)
References <5D3889D2.3090101@tlinx.org>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Trace usenet.stanford.edu 1563986396 4475 209.51.188.17 (24 Jul 2019 16:39:56 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash <bug-bash@gnu.org>
Envelope-to bug-bash@gnu.org
User-Agent Thunderbird
X-detected-operating-system by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic]
X-Received-From 173.164.175.65
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <5D3889D2.3090101@tlinx.org>
Xref csiph.com gnu.bash.bug:15231

Show key headers only | View raw


shopt -o expand_aliases
my=declare int='my -i'
my str='cf80'
int v=960  uxtra=1  c=0

# In evaluating this expression:
  ((v = v | ( uxtra>=++c ? ((0x${str:2*c:2}) & 63) << (6*(uxtra-c)) : 0 )))


I get 985 and not 960 as expected

Which only happens when 'c' is 0 in the middle 'str' expression,
but the ++c should increment 'c' to '1' before it is tested to be
less than or equal to 'uxtra'(=1).  Then it would take the 1st or
2nd sub expression depending on that.  But the test has to happen
1st, which would pre-increment 'c' to 1.  If 'c' is 1, then it should
return '80' from 'str' combine with 0x to make 0x80 or 128.  That,
anded with '63' should be 0, shouldn't it?

So why isn't it evaluating to '0', 'or'ed  with 960, and giving 960?

Indeed, if I manually put a '1' in place of that 'c' in the middle
of the expression, I get the expected answer of 960.  So it seems
'c' is evaluating as '0', even though the middle sub-expression
can't be taken/evaluated until 'c' has been incremented to 1.

BASH=4.4.12

Thanks
-linda

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

expression evaluation problem L A Walsh <bash@tlinx.org> - 2019-07-24 09:39 -0700

csiph-web