Codebase list edid-decode / 9cb3744
edid-decode: fix spurious warning about string termination Fixes bug https://bugs.freedesktop.org/show_bug.cgi?id=93777: The Monitor Name description string can be exactly 13 bytes, which case there is no newline at the end. Yet this was considered an error. Simplify the code by relying on extract_string to do the checking. The extract_string function also checks for trailing spaces and warns about that. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Hans Verkuil 5 years ago
1 changed file(s) with 50 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
5050 static int nonconformant_extension = 0;
5151 static int did_detailed_timing = 0;
5252 static int has_name_descriptor = 0;
53 static int name_descriptor_terminated = 0;
53 static int has_serial_string = 0;
54 static int has_ascii_string = 0;
5455 static int has_range_descriptor = 0;
5556 static int has_preferred_timing = 0;
5657 static int has_valid_checksum = 1;
6061 static int has_valid_dummy_block = 1;
6162 static int has_valid_serial_number = 0;
6263 static int has_valid_serial_string = 0;
64 static int has_valid_ascii_string = 0;
65 static int has_valid_name_descriptor = 0;
6366 static int has_valid_week = 0;
6467 static int has_valid_year = 0;
6568 static int has_valid_detailed_blocks = 0;
6871 static int has_valid_range_descriptor = 1;
6972 static int has_valid_max_dotclock = 1;
7073 static int has_valid_string_termination = 1;
74 static int empty_string = 0;
75 static int trailing_space = 0;
7176 static int has_cta861 = 0;
7277 static int has_640x480p60_est_timing = 0;
7378 static int has_cta861_vic_1 = 0;
404409 }
405410
406411 /* extract a string from a detailed subblock, checking for termination */
407 static char *extract_string(unsigned char *x, int *valid_termination, int len)
412 static char *extract_string(unsigned char *x, int *valid, int len)
408413 {
409414 static char ret[EDID_PAGE_SIZE];
410415 int i, seen_newline = 0;
411416
412417 memset(ret, 0, sizeof(ret));
418 *valid = 1;
413419
414420 for (i = 0; i < len; i++) {
415421 if (isgraph(x[i])) {
417423 } else if (!seen_newline) {
418424 if (x[i] == 0x0a) {
419425 seen_newline = 1;
426 if (!i) {
427 empty_string = 1;
428 *valid = 0;
429 } else if (ret[i - 1] == 0x20) {
430 trailing_space = 1;
431 *valid = 0;
432 }
420433 } else if (x[i] == 0x20) {
421434 ret[i] = x[i];
422435 } else {
423 *valid_termination = 0;
436 has_valid_string_termination = 0;
437 *valid = 0;
424438 return ret;
425439 }
426 } else {
427 if (x[i] != 0x20) {
428 *valid_termination = 0;
429 return ret;
430 }
431 }
440 } else if (x[i] != 0x20) {
441 has_valid_string_termination = 0;
442 *valid = 0;
443 return ret;
444 }
445 }
446 /* Does the string end with a space? */
447 if (!seen_newline && ret[len - 1] == 0x20) {
448 trailing_space = 1;
449 *valid = 0;
432450 }
433451
434452 return ret;
604622 /* 1 means valid data */
605623 static int detailed_block(unsigned char *x, int in_extension)
606624 {
607 static unsigned char name[53];
608625 int ha, hbl, hso, hspw, hborder, va, vbl, vso, vspw, vborder;
609626 int refresh, pixclk_khz;
610627 int i;
725742 return 1;
726743 }
727744 case 0xFC:
728 /* XXX should check for spaces after the \n */
729 /* XXX check: terminated with 0x0A, padded with 0x20 */
730745 has_name_descriptor = 1;
731 if (strchr((char *)name, '\n')) return 1;
732 strncat((char *)name, (char *)x + 5, 13);
733 if (strchr((char *)name, '\n')) {
734 name_descriptor_terminated = 1;
735 printf("Monitor name: %s\n",
736 extract_string(name, &has_valid_string_termination,
737 strlen((char *)name)));
738 }
746 printf("Monitor name: %s\n",
747 extract_string(x + 5, &has_valid_name_descriptor, 13));
739748 return 1;
740749 case 0xFD: {
741750 int h_max_offset = 0, h_min_offset = 0;
892901 * TODO: Two of these in a row, in the third and fourth slots,
893902 * seems to be specified by SPWG: http://www.spwg.org/
894903 */
904 has_ascii_string = 1;
895905 printf("ASCII string: %s\n",
896 extract_string(x + 5, &has_valid_string_termination, 13));
906 extract_string(x + 5, &has_valid_ascii_string, 13));
897907 return 1;
898908 case 0xFF:
909 has_serial_string = 1;
899910 printf("Serial number: %s\n",
900 extract_string(x + 5, &has_valid_string_termination, 13));
901 has_valid_serial_string = 1;
911 extract_string(x + 5, &has_valid_serial_string, 13));
902912 return 1;
903913 default:
904914 printf("Unknown monitor description type %d\n", x[3]);
29342944 !has_valid_string_termination ||
29352945 !has_valid_descriptor_pad ||
29362946 !has_name_descriptor ||
2937 !name_descriptor_terminated ||
29382947 !has_preferred_timing ||
29392948 (!claims_one_point_four && !has_range_descriptor))
29402949 conformant = 0;
29562965 printf("\tHDMI Forum VSDB Max TMDS rate is > 0 and <= 340 or > 600\n");
29572966 if (!has_name_descriptor)
29582967 printf("\tMissing name descriptor\n");
2959 else if (!name_descriptor_terminated)
2960 printf("\tName descriptor not terminated with a newline\n");
29612968 if (!has_preferred_timing)
29622969 printf("\tMissing preferred timing\n");
29632970 if (!has_range_descriptor)
29672974 if (!has_valid_string_termination) /* Likewise */
29682975 printf("\tDetailed block string not properly terminated\n");
29692976 } else if (claims_one_point_two) {
2970 if (nonconformant_digital_display ||
2971 (has_name_descriptor && !name_descriptor_terminated))
2977 if (nonconformant_digital_display)
29722978 conformant = 0;
29732979 if (!conformant)
29742980 printf("EDID block does NOT conform to EDID 1.2!\n");
29752981 if (nonconformant_digital_display)
29762982 printf("\tDigital display field contains garbage: %x\n",
29772983 nonconformant_digital_display);
2978 if (has_name_descriptor && !name_descriptor_terminated)
2979 printf("\tName descriptor not terminated with a newline\n");
29802984 } else if (claims_one_point_oh) {
29812985 if (seen_non_detailed_descriptor)
29822986 conformant = 0;
30163020 !has_valid_dummy_block ||
30173021 !has_valid_descriptor_ordering ||
30183022 !has_valid_range_descriptor ||
3019 !manufacturer_name_well_formed) {
3023 !manufacturer_name_well_formed ||
3024 (has_name_descriptor && !has_valid_name_descriptor) ||
3025 (has_serial_string && !has_valid_serial_string) ||
3026 (has_ascii_string && !has_valid_ascii_string) ||
3027 empty_string ||
3028 trailing_space) {
30203029 conformant = 0;
30213030 printf("EDID block does not conform at all!\n");
30223031 if (nonconformant_extension)
30443053 printf("\tRange descriptor contains garbage\n");
30453054 if (!has_valid_max_dotclock)
30463055 printf("\tEDID 1.4 block does not set max dotclock\n");
3056 if (has_name_descriptor && !has_valid_name_descriptor)
3057 printf("\tInvalid Monitor Name descriptor\n");
3058 if (has_ascii_string && !has_valid_ascii_string)
3059 printf("\tInvalid ASCII string\n");
3060 if (has_serial_string && !has_valid_serial_string)
3061 printf("\tInvalid serial string\n");
3062 if (trailing_space)
3063 printf("\tString contains one or more trailing spaces\n");
3064 if (empty_string)
3065 printf("\tString is empty\n");
30473066 }
30483067
30493068 if (!has_valid_cta_checksum) {