Giorgio,

I believe I know what the problem is.

When you type make safe, it attempts to catch any possibly unsafe 
operations.  Mostly this is concerned with memory access and going 
outside of bounds on an array, etc.

In your example, the operation is not safe.  If for example you did this:

uint8_t oneChar = 'A';
dimImmagine(&oneChar);

Your function now just read some random memory location after &oneChar, 
and compared it with 200.  Now reading memory can't corrupt the kernel, 
or other code, but you can definitely get unpredictable values(from the 
read).

The only safe memory actions that can be done on a pointer is 
reading/writing buf[0].  There is no way to determine what the memory 
bounds of a pointer are, so make safe is going to complain if you 
read/write to any other offset from a pointer.

If you want this code to be safe, you need to change your function 
declaration to something like this:

#define BUF_LENGTH 10

...

void dimImmagine(uint8_t buf1[BUF_LENGTH]);

...


See this website for safe programming on tinyos:

http://docs.tinyos.net/index.php/Safe_TinyOS

-Paul



giorgio wrote:
> I am trying to understand why my program sometimes block using the option 
> safe 
> .I use tinyos 2.1 with telosb .Why is an error the follow code ?
>
>
>               void dimImmagine(uint8_t*buf1)
>                       {
>                               
> 440                           if(buf1[2]==200)
>
>
> when I compile with the option make telosb safe
>
> RadioCImpl.nc:440: Error: Assertion will always fail in upper bound check:
>   buf1 + (2 + 1) <= buf1 + 1
>
> Each help is very important :thank in advance
>
> Giorgio
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>   
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to