| 687 | |
| 688 | |
| 689 | int |
| 690 | parse_hex_line(char *line) |
| 691 | { |
| 692 | int addr, code, num; |
| 693 | int sum, len, cksum, i; |
| 694 | char *ptr; |
| 695 | |
| 696 | num = 0; |
| 697 | if (line[0] != ':') return 0; |
| 698 | if (strlen(line) < 11) return 0; |
| 699 | ptr = line+1; |
| 700 | if (!sscanf(ptr, "%02x", &len)) return 0; |
| 701 | ptr += 2; |
| 702 | if ((int)strlen(line) < (11 + (len * 2)) ) return 0; |
| 703 | if (!sscanf(ptr, "%04x", &addr)) return 0; |
| 704 | ptr += 4; |
| 705 | /* printf("Line: length=%d Addr=%d\n", len, addr); */ |
| 706 | if (!sscanf(ptr, "%02x", &code)) return 0; |
| 707 | if (addr + extended_addr + len >= MAX_MEMORY_SIZE) return 0; |
| 708 | ptr += 2; |
| 709 | sum = (len & 255) + ((addr >> 8) & 255) + (addr & 255) + (code & 255); |
| 710 | if (code != 0) { |
| 711 | if (code == 1) { |
| 712 | end_record_seen = 1; |
| 713 | return 1; |
| 714 | } |
| 715 | if (code == 2 && len == 2) { |
| 716 | if (!sscanf(ptr, "%04x", &i)) return 1; |
| 717 | ptr += 4; |
| 718 | sum += ((i >> 8) & 255) + (i & 255); |
| 719 | if (!sscanf(ptr, "%02x", &cksum)) return 1; |
| 720 | if (((sum & 255) + (cksum & 255)) & 255) return 1; |
| 721 | extended_addr = i << 4; |
| 722 | //printf("ext addr = %05X\n", extended_addr); |
| 723 | } |
| 724 | if (code == 4 && len == 2) { |
| 725 | if (!sscanf(ptr, "%04x", &i)) return 1; |
| 726 | ptr += 4; |
| 727 | sum += ((i >> 8) & 255) + (i & 255); |
| 728 | if (!sscanf(ptr, "%02x", &cksum)) return 1; |
| 729 | if (((sum & 255) + (cksum & 255)) & 255) return 1; |
| 730 | extended_addr = i << 16; |
| 731 | //printf("ext addr = %08X\n", extended_addr); |
| 732 | } |
| 733 | return 1; // non-data line |
| 734 | } |
| 735 | byte_count += len; |
| 736 | while (num != len) { |
| 737 | if (sscanf(ptr, "%02x", &i) != 1) return 0; |
| 738 | i &= 255; |
| 739 | firmware_image[addr + extended_addr + num] = i; |
| 740 | firmware_mask[addr + extended_addr + num] = 1; |
| 741 | ptr += 2; |
| 742 | sum += i; |
| 743 | (num)++; |
| 744 | if (num >= 256) return 0; |
| 745 | } |
| 746 | if (!sscanf(ptr, "%02x", &cksum)) return 0; |
no test coverage detected
searching dependent graphs…