problem with G_get_map_row()

I am trying to read a layer by masking each category number and
trying to get stats like number of cells in that category etc...

After I successfully masked the category number of interest
when I use the G_get_map_row it reads the category numbers
outside of mask area in to its buf. But if I use a system call
to say r.stats it gives stats for only the masked area.

My main goal is to get window coordinate system for each one
of such category number and I will mask that area to extract
different layers of information which would eleminate reading
from other areas that are not useful for processing and save time
in doing so.

Can any one tell me why I am reading category numbers outside my
mask area.

P.S :- The mask I am creating for each category number is using
a system command to r.reclass

Srinivasan.
srin@brcsun1.tamu.edu