check if color specified before conversion to hex

this allows black to be written instead of returning the pixel value
This commit is contained in:
xfnw 2021-08-21 15:09:56 -04:00
parent 6b62d31dc5
commit d3e9803cf2
1 changed files with 4 additions and 4 deletions

View File

@ -40,17 +40,17 @@ void *handle_connection(void *socket_desc) {
int ypos = atoi(safestrtok(NULL, " \n"));
char colorcode[8];
strncpy(colorcode, safestrtok(NULL, " \n"), 8);
//if (strlen(colorcode) < 2*fb_bytes)
// strcat(colorcode, "00");
int color = (int)strtol(colorcode, NULL, 16);
if (xpos >= 0 && ypos >= 0 && xpos < fb_width && ypos < fb_height) {
if (color == 0) {
if (strlen(colorcode) == 0) {
message = calloc(sizeof(char), 36);
asprintf(&message, "PX %i %i %X\n",xpos,ypos,fbdata[ypos*fb_length+xpos]);
write(sock, message, strlen(message));
continue;
} else {
//if (strlen(colorcode) < 2*fb_bytes)
// strcat(colorcode, "00");
int color = (int)strtol(colorcode, NULL, 16);
fbdata[ypos*fb_length+xpos] = color;
}
}