gpgscm: Simplify get-output-string operation.
authorJustus Winter <justus@g10code.com>
Tue, 4 Apr 2017 15:38:50 +0000 (17:38 +0200)
committerJustus Winter <justus@g10code.com>
Tue, 4 Apr 2017 16:19:35 +0000 (18:19 +0200)
* tests/gpgscm/scheme.c (opexe_4): Simplify 'get-output-string'.

Signed-off-by: Justus Winter <justus@g10code.com>
tests/gpgscm/scheme.c

index 3c7afa3..736486f 100644 (file)
@@ -4811,20 +4811,12 @@ static pointer opexe_4(scheme *sc, enum scheme_opcodes op) {
           port *p;
 
           if ((p=car(sc->args)->_object._port)->kind&port_string) {
-               off_t size;
-               char *str;
-
-               size=p->rep.string.curr-p->rep.string.start+1;
-               str=sc->malloc(size);
-               if(str != NULL) {
-                    pointer s;
-
-                    memcpy(str,p->rep.string.start,size-1);
-                    str[size-1]='\0';
-                    s=mk_string(sc,str);
-                    sc->free(str);
-                    s_return(sc,s);
-               }
+              gc_disable(sc, 1);
+              s_return_enable_gc(
+                   sc,
+                   mk_counted_string(sc,
+                                     p->rep.string.start,
+                                     p->rep.string.curr - p->rep.string.start));
           }
           s_return(sc,sc->F);
      }