assert(ucslen(lto->decodedOutput) == lto->decodedChars);
assert((int)ucslen(lto->decodedOutput) == lto->decodedChars);
static int ltermReturnStreamData(struct lterms *lts, struct LtermRead *ltr){  struct LtermOutput *lto = &(lts->ltermOutput);  UNICHAR *locTerminator;  int streamTerminated, charCount, deleteCount, j;  LTERM_LOG(ltermReturnStreamData,30,("start\n"));  if (lto->decodedChars == 0)    return 0;  ltr->opcodes = LTERM_STREAMDATA_CODE | lto->streamOpcodes;  if (ucslen(lto->streamTerminator) == 0) {    /* Null terminated stream */    locTerminator = NULL;    for (j=0; j<lto->decodedChars; j++) {      if (lto->decodedOutput[j] == 0) {        locTerminator = &lto->decodedOutput[j];        break;      }    }  } else {    /* Non-null terminated stream */    assert(lto->decodedChars < MAXCOL);    /* Insert terminating null character in decoded buffer */    lto->decodedOutput[lto->decodedChars] = U_NUL;    /* There should be no NULs in decoded output */    assert(ucslen(lto->decodedOutput) == lto->decodedChars);    /* Search for stream terminator string in decoded output */    locTerminator = ucsucs(lto->decodedOutput, lto->streamTerminator);  }  /* Stream termination flag */  streamTerminated = 0;  if (locTerminator == NULL) {    /* No terminator found; return decoded stream data */    charCount = lto->decodedChars;    if (charCount > ltr->max_count)      charCount = ltr->max_count;  } else {    /* Count stream portion of decoded output (excluding terminator) */    charCount = locTerminator - lto->decodedOutput;    if (charCount > ltr->max_count) {      /* Return only portion of stream data that fits into output buffer,       * without terminating stream mode       */      charCount = ltr->max_count;    } else {      /* Return all remaining stream data, terminate stream mode and       * revert to saved output mode       */      streamTerminated = 1;      if (lto->savedOutputMode == LTERM1_SCREEN_MODE) {        if (ltermSwitchToScreenMode(lts) != 0)          return -1;      } else {        if (ltermSwitchToLineMode(lts) != 0)          return -1;      }      LTERM_LOG(ltermReturnStreamData,22,("terminating STREAM mode\n"));    }  }  /* Copy stream data to output buffer */  for (j=0; j<charCount; j++) {    ltr->buf[j] = lto->decodedOutput[j];    ltr->style[j] = LTERM_STDOUT_STYLE;  }  /* Count of characters read */  ltr->read_count = charCount;  /* Count of characters to be deleted */  deleteCount = charCount;  if (streamTerminated) {    /* Stream terminated */    ltr->opcodes |= LTERM_NEWLINE_CODE;    /* Delete terminator string from decoded buffer */    if (ucslen(lto->streamTerminator) == 0) {      deleteCount += 1;    } else {      deleteCount += ucslen(lto->streamTerminator);    }  }  /* Shift remaining characters in decoded buffer */  for (j=deleteCount; j<lto->decodedChars; j++)    lto->decodedOutput[j-deleteCount] = lto->decodedOutput[j];  lto->decodedChars -= deleteCount;  LTERM_LOG(ltermReturnStreamData,31,("returning STREAM data (%d bytes)\n",                                         ltr->read_count));  return 0;}