Skip to content

Commit

Permalink
Fixed segmentation fault for gismeteo data
Browse files Browse the repository at this point in the history
  • Loading branch information
vasvlad committed Dec 21, 2024
1 parent 2d1c27b commit 24250a9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
meecast (1.11.14)
* Fixed segmentation fault for gismeteo data

meecast (1.11.13)
* Changed url for hourly weather forecast from gismeteo again
* Fixed bug - Since version 1.11.8 of MeeCast, no clickable list for the forecast and Pulley-Menu broken #79
Expand Down
2 changes: 2 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
meecast (1.11.14) unstable; urgency=low
* Added icons to gismeteo.ru
* Fixed segmentation fault for gismeteo data
-- Vlad Vasiliev <[email protected]> Fri, 21 Dec 2024 12:02:23 +0300

meecast (1.11.13) unstable; urgency=low
Expand Down
28 changes: 19 additions & 9 deletions omweather-gismeteo-ru-stations-db/src/meego-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,8 @@ gismeteoru_parse_and_write_xml_data(const char *station_id, htmlDocPtr doc, cons
xpathObjDescription = xmlXPathEvalExpression((const xmlChar*)"/html/body/main/div[1]/section[2]/div[1]/div/div/div[2]/div[@data-tooltip]", xpathCtx);
xpathObjMaxPressure = xmlXPathEvalExpression((const xmlChar*)"/html/body/main/*//div[@class='widget-row-chart widget-row-chart-pressure row-with-caption' ]/div/div[@class='values']/div[@class='value']/div[@class='maxt']/pressure-value", xpathCtx);
xpathObjWindSpeed = xmlXPathEvalExpression((const xmlChar*)"/html/body/main/*//div[@class='widget-row widget-row-wind row-wind-speed row-with-caption' ]/div//speed-value", xpathCtx);
xpathObjWindGust = xmlXPathEvalExpression((const xmlChar*)"/html/body/main/*//div[@class='widget-row widget-row-wind row-wind-gust row-with-caption' ]/div//speed-value", xpathCtx);
//xpathObjWindGust = xmlXPathEvalExpression((const xmlChar*)"/html/body/main/*//div[@class='widget-row widget-row-wind row-wind-gust row-with-caption' ]/div//speed-value", xpathCtx);
xpathObjWindGust = xmlXPathEvalExpression((const xmlChar*)"/html/body/main/*//div[@class='widget-row widget-row-wind row-wind-gust row-with-caption' ]/div[@class='row-item']", xpathCtx);
xpathObjWindDirection = xmlXPathEvalExpression((const xmlChar*)"/html/body/main/*//div[@class='widget-row widget-row-wind row-wind-direction row-with-caption' ]/div//div[@class='direction']/text()", xpathCtx);
xpathObjHumidity = xmlXPathEvalExpression((const xmlChar*)"/html/body/main/*//div[@class='widget-row widget-row-humidity row-with-caption']/div/text()", xpathCtx);
xpathObjUv = xmlXPathEvalExpression((const xmlChar*)"/html/body/main/*//div[@class='widget-row widget-row-radiation row-with-caption']/div/text()", xpathCtx);
Expand Down Expand Up @@ -622,14 +623,23 @@ gismeteoru_parse_and_write_xml_data(const char *station_id, htmlDocPtr doc, cons
/* added wind gust */
memset(buffer, 0, sizeof(buffer));
if (xpathObjWindGust && !xmlXPathNodeSetIsEmpty(xpathObjWindGust->nodesetval) &&
xpathObjWindGust->nodesetval->nodeTab[i]){
/* Normalize speed to km/h from m/s */
/* fprintf(stderr, "Wind speed \n"); */
xmlChar *temp_xml_string = NULL;
temp_xml_string = (xmlChar*)xmlGetProp(xpathObjWindGust->nodesetval->nodeTab[i], (xmlChar*) "value");
snprintf(buffer, sizeof(buffer)-1,"%s", temp_xml_string);
speed = atoi ((char *)buffer);
fprintf(file_out," <wind_gust>%1.f</wind_gust>\n", (double)(speed));
xpathObjWindGust->nodesetval->nodeTab[i] && xpathObjWindGust->nodesetval->nodeTab[i]->children){
/* Normalize speed to km/h from m/s */
xmlChar *temp_xml_string = NULL;
temp_xml_string = xmlGetProp(xpathObjWindGust->nodesetval->nodeTab[i]->children, (xmlChar*) "class");
if (temp_xml_string && (strncmp((char *)temp_xml_string, "item-bg", strlen((char *)temp_xml_string)) == 0)){
for (xmlNodePtr iter_node = xpathObjWindGust->nodesetval->nodeTab[i]->children; iter_node; iter_node = iter_node->next){
if (iter_node->type == XML_ELEMENT_NODE){
if ((strncmp((char *)iter_node->name, "speed-value", strlen((char *)iter_node->name)) == 0)){
xmlChar *temp_xml_string1 = (xmlChar*)xmlGetProp(iter_node, (xmlChar*) "value");
snprintf(buffer, sizeof(buffer)-1,"%s", temp_xml_string1);
speed = atoi ((char *)buffer);
fprintf(file_out," <wind_gust>%1.f</wind_gust>\n", (double)(speed));
xmlFree(temp_xml_string1);
}
}
}
}
xmlFree(temp_xml_string);
}

Expand Down
5 changes: 3 additions & 2 deletions omweather-gismeteo-ru-stations-db/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
./gismeteoru ./examples/weekly.html ./examples/out.xml ./examples/hourly.html
#./gismeteoru ./examples/weekly.html ./examples/out.xml ./examples/hourly.html
# ./gismeteoru ./examples/weekly.html ./examples/out.xml
#valgrind --tool=memcheck --log-file=1.log -v --track-origins=yes --leak-check=full --show-reachable=yes ./gismeteoru ./examples/weekly.html ./examples/out.xml ./examples/hourly.html
valgrind --tool=memcheck --log-file=1.log -v --track-origins=yes --leak-check=full --show-reachable=yes ./gismeteoru ./examples/weekly.html ./examples/out.xml ./examples/hourly.html
#valgrind --tool=memcheck --log-file=1.log -v --track-origins=yes --leak-check=full --show-reachable=yes ./gismeteoru ./examples/weekly.html ./examples/out.xml

0 comments on commit 24250a9

Please sign in to comment.