[sr-dev] [kamailio/kamailio] pv: log uninit $var() (PR #3114)

Daniel-Constantin Mierla notifications at github.com
Tue May 17 13:49:09 CEST 2022


@smititelu - that note from the docs sounds ok for me (maybe because I wrote it, although I am not sure I did). Practically wants to say that assign explicitly a value before using it, not to get the value set a while ago in another SIP message processing context.

If you do:

```
request_route {
...
  while ($var(i) < 100) {
    ...
    $var(i) = $var(i) + 1;
  }
...
}
```

The while loop gets inside once because  $var(i) is 0 first time, but then remains set to 100 for all next requests. Therefore set it to the value you want before using it:

```
request_route {
...
  $var(i) = 0;
  while ($var(i) < 100) {
    ...
    $var(i) = $var(i) + 1;
  }
...
}
```

Feel free to change the statement in the docs, if you consider more clarifications there, but I don't see any benefit in storing an extra int field in the internal var structure.

Maybe $vn() offers better the kind of variable you need. It is like $var() but can have $null value (state).

-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/3114#issuecomment-1128770857
You are receiving this because you are subscribed to this thread.

Message ID: <kamailio/kamailio/pull/3114/c1128770857 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-dev/attachments/20220517/501c97f4/attachment-0001.htm>


More information about the sr-dev mailing list