CASE WITHOUT OTHERWISE BREAKS STACK
Posted in 1991
Topics: Stored Procedures & SPL, Connectivity: ESQL/C, 4GL & Embedded SQL
We are running sql 2.10.00B, with a c4gl that "what's" as ver 4.7 2/25/87 on an Intel 320 with Xenix 3.5. We found that a case statement like the following: CASE ( stat ) WHEN RP_DEL display "A DEL" WHEN RP_ADD display "AN ADD" END CASE will leave an extra value on the stack if none of the cases are selected. (RP_DEL and RP_ADD are variables with same type as stat and have legitimate values.) I discovered this when one function kept returning one bogus value followed by the remaining intended values. The c code from one broken program looks something like this: pushlong(stat); <----- case selector on stack pushlong(rp_del); <----- first test value on stack _doeqnopop(); <---- doesn't pop anything.. yes ???? popbool(&fgl_case); <---- pops one value???? if(fgl_case) { <---- IF MATCH --- popdummy(); <---- takes selector off stack?? goto ll1; <---- an exit while instruction (bleeaah) goto ll0; <---- branch to end case label } and repeated for each case, and then the concluding } at END CASE. When an OTHERWISE clause with no statements is added, the following code comes in.. <--- located such that you just fall in to it popdummy(); if you haven't yet goto'd before this goto l10; <--- branch to end case label So it appears that the selector value comes off the stack on a match, or if there is an OTHERWISE to consume it. Otherwise, you've got this extra value floating around on the stack. What's cute is to put one of these case statements in an infinite loop and watch it coredump when your stack finally gets a memory violation. TFM says that the OTHERWISE case is optional, and says nothing about requiring a match on one of the listed cases. Am I missing something?? Is this something fixed in a later release?? ----------------------------------------------------------------------------- | Bruce Funk INTERNET: funkb@zweibrucken-emh1.army.mil| |C, *IX SUPPORT TEAM AUTOVON/ETS: 494-6786 | |USAISEC-EUR (MINI/MICRO DIV)________________________________________________| |BOX 153 | Any resemblance between me and reality | |APO NY, 09052-5905 | is strictly coincidental | -----------------------------------------------------------------------------