I removed the greater than 255 check because you can't really test against that. If bg or fg have any attributes set then the value will be greater than 255; but if you mask the upper byte then it can't be greater than 255 anyway. (As-is they wouldn't necessarily be set to white either, they would be set to the lower byte of the color.)

If you really want to allow some kind of graceful overflow then either attributes would have to be stored separately, or you would have to define the range that you will allow overflows in, so that attributes can be placed outside of that range. (And since there will always have to be _some_ defined range that values aren't valid outside of, why not just call it 0-255?)