[hackers] [sbase] subtract 'a' from indices for marks || Evan Gates

From: <git_AT_suckless.org>
Date: Wed, 3 Aug 2016 16:35:49 +0200 (CEST)

commit e3f497e1f6b2a4b7c24011c493705d8e34f09d83
Author: Evan Gates <evan.gates_AT_gmail.com>
AuthorDate: Fri Jul 15 09:57:50 2016 -0700
Commit: sin <sin_AT_2f30.org>
CommitDate: Wed Aug 3 15:35:36 2016 +0100

    subtract 'a' from indices for marks
    
    Given:
    
    static int marks['z' - 'a'];
    marks[c];
    
    In this case c is the character read and index is out of bounds. We
    need marks[c - 'a']
    
    While playing around with optimization settings gcc caught caught this.
    
    Also fix one check for c, change from isalpha to islower.
    
    -emg
    
    From 2cc36818283e9068576c1042690c016a81b709a3 Mon Sep 17 00:00:00 2001
    From: Evan Gates <evan.gates_AT_gmail.com>
    Date: Fri, 15 Jul 2016 09:52:39 -0700
    Subject: [PATCH] fix marks indexing

diff --git a/ed.c b/ed.c
index ce19cf7..184ed30 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -478,9 +478,9 @@ linenum(int *line)
                 break;
         case '\'':
                 skipblank();
- if (!isalpha(c = input()))
+ if (!islower(c = input()))
                         error("invalid mark character");
- if (!(ln = marks[c]))
+ if (!(ln = marks[c - 'a']))
                         error("invalid address");
                 break;
         case '$':
_AT_@ -1191,7 +1191,7 @@ repeat:
                         error("invalid mark character");
                 chkprint(1);
                 deflines(curln, curln);
- marks[c] = line1;
+ marks[c - 'a'] = line1;
                 break;
         case 'P':
                 if (nlines > 0)
Received on Wed Aug 03 2016 - 16:35:49 CEST

This archive was generated by hypermail 2.3.0 : Wed Aug 03 2016 - 16:36:14 CEST