- memset(TileBuf, ' ', Pegs[peg].Length[SlotNo]);
- TileBuf[Pegs[peg].Length[SlotNo]] = '\0';
- if (has_colors())
- attrset(COLOR_PAIR(LENTOIND(Pegs[peg].Length[SlotNo])));
- else
- attrset(A_REVERSE);
- mvaddstr(BASELINE - (SlotNo + 1),
- (int) (PegPos[peg] - Pegs[peg].Length[SlotNo] / 2),
- TileBuf);
+ unsigned len = Pegs[peg].Length[SlotNo];
+ if (len < sizeof(TileBuf) - 1 && len < (unsigned) PegPos[peg]) {
+ memset(TileBuf, ' ', len);
+ TileBuf[len] = '\0';
+ if (has_colors())
+ attrset(COLOR_PAIR(LENTOIND(len)));
+ else
+ attrset(A_REVERSE);
+ mvaddstr(BASELINE - (SlotNo + 1),
+ (int) (PegPos[peg] - len / 2),
+ TileBuf);
+ }