comparison arch/io.c @ 4:e2b1d6184703

getline: don't touch bytes past the end of the buffer
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Wed, 09 Mar 2011 18:21:44 -0500
parents 68bac03da6ff
children 0451ffa1c3a0
comparison
equal deleted inserted replaced
3:ec991c3809db 4:e2b1d6184703
540 return len; 540 return len;
541 } 541 }
542 542
543 int getline(char *buf, int len) 543 int getline(char *buf, int len)
544 { 544 {
545 int i;
546
545 if (!init_cons) 547 if (!init_cons)
546 enable_cons(CON_DEV); 548 enable_cons(CON_DEV);
547 549
548 if ((len <= 0) || (len > CON_LEN)) 550 if ((len <= 0) || (len > CON_LEN))
549 return -1; 551 return -1;
550 552
551 wait_for_io_int(); 553 wait_for_io_int();
552 554
553 __builtin_memset(buf, 0, CON_LEN); 555 __builtin_memset(buf, 0, len);
554 ccw.cmd = 0x0a; 556 ccw.cmd = 0x0a;
555 ccw.flags = 0x20; 557 ccw.flags = 0x20;
556 ccw.count = len; 558 ccw.count = len;
557 ccw.addr = (u32) (u64) buf; 559 ccw.addr = (u32) (u64) buf;
558 560
564 if (start_sch(consch, &orb)) 566 if (start_sch(consch, &orb))
565 die(); 567 die();
566 568
567 wait_for_io_int(); 569 wait_for_io_int();
568 570
569 for(len=0; len<CON_LEN; len++) 571 for(i=0; i<len; i++)
570 if (!buf[len]) 572 if (!buf[i])
571 break; 573 break;
572 574
573 if (len) 575 if (i)
574 ebcdic2ascii((u8*) buf, len); 576 ebcdic2ascii((u8*) buf, i);
575 577
576 return len; 578 return i;
577 } 579 }