cmyth_get_bookmark_offset wrong return type

MythTV
2010-05-01
2013-06-03
  • Bruce Elmore
    Bruce Elmore
    2010-05-01

    I'm not sure what forum that I should be posting this in, however, the cmyth_get_bookmark_offset function in the cymth library has a bug in it. It finds the byte offset for a frame mark for a particular mythtv recording. Unfortunately, it's returning an int instead of a long long.

    Here's the fixed version:

    long long
    cmyth_get_bookmark_offset(cmyth_database_t db, long chanid, long long mark, char *starttime, int mode)
    {
    MYSQL_RES *res = NULL;
    MYSQL_ROW row;
    //int offset=0;
    long long offset = 0;
    int rows = 0;
    int rectype = 0;
    cmyth_mysql_query_t * query;

    //const char *query_str = "SELECT * FROM recordedseek WHERE chanid = ? AND mark= ? AND starttime = ?;";
    const char *query_str = "SELECT * FROM recordedseek WHERE chanid = ? AND mark<= ? AND starttime = ? ORDER BY MARK DESC LIMIT 1;";

    query = cmyth_mysql_query_create(db,query_str);
    if (cmyth_mysql_query_param_long(query, chanid) < 0
    || cmyth_mysql_query_param_long(query, mark) < 0
    || cmyth_mysql_query_param_str(query, starttime) < 0
    ) {
    cmyth_dbg(CMYTH_DBG_ERROR,"%s, binding of query parameters failed! Maybe we're out of memory?\n", __FUNCTION__);
    ref_release(query);
    return -1;
    }
    res = cmyth_mysql_query_result(query);
    ref_release(query);
    if (res == NULL) {
    cmyth_dbg(CMYTH_DBG_ERROR, "%s, finalisation/execution of query failed!\n", __FUNCTION__);
    return -1;
    }
    while ((row = mysql_fetch_row(res))) {
    //offset = safe_atoi(row);
    offset = safe_atoll(row);
    rectype = safe_atoi(row);
    rows++;
    }
    if (rectype != 9) {
    if (mode == 0) {
    mark=(mark/15)+1;
    }
    else if (mode == 1) {
    mark=(mark/12)+1;
    }
    query = cmyth_mysql_query_create(db,query_str);
    if (cmyth_mysql_query_param_long(query, chanid) < 0
    || cmyth_mysql_query_param_long(query, mark) < 0
    || cmyth_mysql_query_param_str(query, starttime) < 0
    ) {
    cmyth_dbg(CMYTH_DBG_ERROR,"%s, binding of query parameters failed! Maybe we're out of memory?\n", __FUNCTION__);
    ref_release(query);
    return -1;
    }
    res = cmyth_mysql_query_result(query);
    ref_release(query);
    if (res == NULL) {
    cmyth_dbg(CMYTH_DBG_ERROR, "%s, finalisation/execution of query failed!\n", __FUNCTION__);
    return -1;
    }
    while ((row = mysql_fetch_row(res))) {
    //offset = safe_atoi(row);
    offset = safe_atoll(row);
    rectype = safe_atoi(row);
    rows++;
    }
    }
    mysql_free_result(res);
    return offset;
    }

    Note this still has another bug that I didn't fix. The mark parameter is a long long and it's being downcast to a long when the MYSQL call is made. I doubt this bug will ever cause in problems since I don't think a frame mark value will ever realistically exceed the max value of a long.

     
  • Tom Metro
    Tom Metro
    2010-05-03

    I'm not sure what forum that I should be posting this in…

    Please send patches and other development related discussion to the mvpmc-devel mailing list.